怎么将从servlet拿到的list集合用json数据显示到jsp页面!

2024-12-24 18:02:47
推荐回答(1个)
回答1:

public void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
JSONObject json = new JSONObject();
json.put("data1", "1233");
json.put("data2", "2344");
ServletOutputStream os = resp.getOutputStream();
os.write(json.toString().getBytes());
os.flush();
os.close();
}
list转JSON时需要用循环进行处理,并将对应的KEY写入到JSON中