前端发送异步请求后台servlet怎么处理

异步操作集合传值需要把集合封装成Json,然后传到前端,需要用到一个转Json的gson-2.3.1.jar包

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json");
        String id = request.getParameter("zid");
        int zid = Integer.parseInt(id);
        Type_ser t= new Type_ser();
        List chakan = t.chakantype(zid);
        
        Gson g = new Gson();
        String ty = g.toJson(chakan);
        PrintWriter out = response.getWriter();
        out.write(ty);
        out.close();
    }

你可能感兴趣的:(前端发送异步请求后台servlet怎么处理)