Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将数据发送到android中的HTTPservlet_Java_Android_Http_Servlets_Client Server - Fatal编程技术网

Java 将数据发送到android中的HTTPservlet

Java 将数据发送到android中的HTTPservlet,java,android,http,servlets,client-server,Java,Android,Http,Servlets,Client Server,这是JavaME中的servlet代码 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); ArrayList<String> listName = new ArrayList<String>(

这是JavaME中的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;

        ...
受保护的void doGet(HttpServletRequest请求,HttpServletResponse响应)抛出ServletException,IOException{
PrintWriter out=response.getWriter();
ArrayList listName=新的ArrayList();
ArrayList List经度=新的ArrayList();
ArrayList listLatitude=新的ArrayList();
String sLongitude=(String)request.getParameter(“x”);
String sLatitude=(String)request.getParameter(“y”);
字符串路径,列表,搜索;
整数numLong=null;
整数numLati=null;
连接con=null;
字符串slanje=“”;
int limitLeft、limitRight、limitUp、limitDown、icount=0;
if(sLongitude!=null&&sLatitude!=null){
试一试{
numLong=整数.valueOf(sLongitude);
numLati=整数.valueOf(sLatitude);
}捕获(例外情况除外){}
}
试一试{
forName(“org.apache.derby.jdbc.ClientDriver”);
con=DriverManager.getConnection(“jdbc:derby://localhost:1527/bazaprojekt“,“项目2009”,“midlet”);
limitLeft=numLong-8;
limitRight=numLong+8;
limitUp=numLati+8;
...

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

只需在servlet的URL之后的查询字符串中将它们作为请求参数传递:


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

只需将它们作为请求参数传递到Servlet URL后面的查询字符串中:


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

如果使用PostMethod,可以使用PostMethod.addParameter进行设置。

如果使用PostMethod,可以使用PostMethod.addParameter进行设置