devcodes
devcodes

Reputation: 1088

Servlet equivalent in Python?

On client side , following android code would make the call to the local server :

        String link = "http://localhost:8080/test/cgi-bin/test.py";
        URL url = null;
        try {
            url = new URL(link);

        HttpURLConnection client =  (HttpURLConnection) url.openConnection();

            JSONObject jo = new JSONObject();
            jo.put("desc","xyz");

            String data2 =  jo.toString();
            client.setRequestMethod("Post");
        //    client.setRequestProperty("key","value");
            client.setDoOutput(true);

            OutputStreamWriter outputPost = new OutputStreamWriter(client.getOutputStream());
            outputPost.write(data2);
            outputPost.flush();
            outputPost.close();

Earlier I was using servlets to interact with DB as the code below : Using HttpServlet class , i could get the request and its parameters :

public class ServletXYZ extends HttpServlet {

 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

        String method = request.getParameter("method");

Is there any way in python which allows me to do the same (getting parameter values from request) ?

Thanks.

Upvotes: 0

Views: 10744

Answers (1)

stdunbar
stdunbar

Reputation: 17435

I've used CherryPy as a general purpose HTTP server framework. Ultimately to do the same as the servlet, there are many links - this one seems to be pretty much what you want.

Upvotes: 3

Related Questions