简体   繁体   English

将数据发送到android中的HTTPservlet

[英]Send data to HTTPservlet in android

This is the servlet code in java ME. 这是java ME中的servlet代码。

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();

    ArrayList<String> listName = new ArrayList<String>();
    ArrayList<Integer> listLongitude = new ArrayList<Integer>();
    ArrayList<Integer> listLatitude = new ArrayList<Integer>();

    String sLongitude = (String) request.getParameter("x");
    String sLatitude = (String) request.getParameter("y");
    String path, list, scount;
    Integer numLong = null;
    Integer numLati = null;
    Connection con = null;
    String slanje = "";
    int limitLeft, limitRight, limitUp, limitDown, icount = 0;

    if (sLongitude != null && sLatitude != null) {
        try {
            numLong = Integer.valueOf(sLongitude);
            numLati = Integer.valueOf(sLatitude);
        } catch(Exception ex) {}
    }

    try{
        Class.forName("org.apache.derby.jdbc.ClientDriver");
        con = DriverManager.getConnection("jdbc:derby://localhost:1527/bazaprojekt", "projekt2009", "midlet");
        limitLeft = numLong - 8;
        limitRight = numLong + 8;
        limitUp = numLati + 8;

        ...

How do I send x and y to servlet and receive some string in Android? 如何在Android中将x和y发送到servlet并接收一些字符串?

Just pass them as request parameters in the query string after the Servlet's URL: 只需将它们作为请求参数传递到Servlet URL之后的查询字符串中即可:

http://example.com/context/servlet?x=123&y=456 . http://example.com/context/servlet?x=123&y=456

如果您使用的是PostMethod,则可以使用PostMethod.addParameter进行设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM