每日学习
今天补说一下后端对okhttp获取数据时的处理:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String classify=request.getParameter("classify");
Dao dao=new Dao();
List<News> list=new ArrayList();
list=dao.selectdata(classify);
String json="{}";
ObjectMapper om=new ObjectMapper(); //需要导包jackson
json=om.writeValueAsString(list);
PrintWriter out=response.getWriter();
System.out.println(json.toString());
out.println(json);
out.flush();
out.close();
}
和寻常的web前端页面获取数据没有天大区别,
这里也可以看到其中返回app的数据,和之前写的博客中对数据的处理相对应

浙公网安备 33010602011771号