在请求中设置对象并从jsp中检索

时间:2014-04-08 19:59:12

标签: ajax servlets

我正在使用org.codehaus.jackson.map.ObjectMapper来返回一个Jason对象。我将列表保留在请求中但无法从jsp访问它。还有其他办法吗?

       response.setContentType("application/json");
        response.setHeader("cache-control", "no-cache");
        ObjectMapper mapper = new ObjectMapper();


        try {
            ArrayList list = cservice.getPolicyList(lastName);

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        if(amount > 0){
            request.setAttribute("dataList", list);

            result =  "{\"success\": true,\"amount\"}";
        }else{
            result =  "{\"success\": false,\"message\": \"We could not find any records. Please verify your search criteria.\"}";
        }

        //Finally send the jason response                   
        OutputStream out = response.getOutputStream();
        mapper.writeValue(out, result);

0 个答案:

没有答案