2009-12-30 62 views
0

这是java ME中的servlet代码。在android中发送数据到HTTPservlet

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; 

     ... 

如何发送x和y到servlet并在Android中接收一些字符串?

回答

2

只是将它们作为在Servlet的URL之后的查询字符串请求参数:

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

1

如果您使用PostMethod,则可以使用PostMethod.addParameter设置它们。