如何使用volley传递给jsp服务器并返回json响应

时间:2017-11-10 12:24:25

标签: jsp android-volley

我正在尝试使用Volley从JSP服务器获取JSON响应。连接没有任何问题,但服务器没有获取已发送的数据。即,

request.getParameter(UID) returns null.

Billow是我用过的代码..请检查一下。

StringRequest stringRequest=new StringRequest(Request.Method.GET,url,new Response.Listener<String>() {
        @Override
        public void onResponse(String s) {
            try {

                Toast.makeText(getApplicationContext(),s+"",Toast.LENGTH_LONG).show();

            }catch (Exception e)
            {
                Toast.makeText(getApplicationContext(),e+"",Toast.LENGTH_LONG).show();
            }
        }
    },new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {

        }
    }){

        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String,String> map=new HashMap<>();
            map.put("UID",id);
            return map;

        }
    };

    requestQueue= Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);

JSP

String sql="SELECT bus.Type,booking.Date,timing.Time,timing.Start,timing.Route,timing.End,bus.Regno FROM timing INNER JOIN bus on timing.Bus=bus.Id INNER JOIN booking on booking.Tid=timing.Id and booking.Status=1 AND booking.Uid='"+request.getParameter("UID")+"'";        
        System.out.println(sql);
        ResultSet rs= new Database().QueryExicute(sql);
        JSONArray array=new JSONArray();
        while(rs.next())
        {

            JSONObject jSONObject=new JSONObject();
            jSONObject.put("BusType",rs.getString(1));
            jSONObject.put("BookingDate",rs.getString(2));
            jSONObject.put("Time",rs.getString(3));
            jSONObject.put("Depot",rs.getString(4));
            jSONObject.put("End",rs.getString(5));  
            jSONObject.put("Start",rs.getString(6));
            jSONObject.put("reg",rs.getString(7));
            array.put(jSONObject);
        }
        PrintWriter printWriter=response.getWriter();
        printWriter.print(array);

1 个答案:

答案 0 :(得分:0)

将请求方法更改为POST及其正常工作