Servlet相当于Python?

时间:2016-08-20 22:26:40

标签: java android python servlets

在客户端,以下android代码将调用本地服务器:

        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();

之前我使用servlet与DB交互,如下面的代码: 使用HttpServlet类,我可以得到请求及其参数:

public class ServletXYZ extends HttpServlet {

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

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

在python中有什么方法可以让我做同样的事情(从请求中获取参数值)?

感谢。

1 个答案:

答案 0 :(得分:3)

我使用CherryPy作为通用HTTP服务器框架。最终与servlet一样,有很多链接 - this one似乎是你想要的。