81,092
社区成员
发帖
与我相关
我的任务
分享
public String execute()
{
List<Room> roomlist=roomService.findAllRoom();
ServletActionContext.getRequest().setAttribute("roomlist", roomlist);
System.out.println("查找完毕");
this.setTotalCount(roomlist.size());
JSONArray array=JSONArray.fromObject(roomlist);
this.jsonString="{totalCount:"+this.getTotalCount()+",results:"+array.toString()+"}";
/*return SUCCESS;*/
System.out.println("转换完毕");
只是你要去引入包
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name=request.getParameter("name");;
out.println("<?xml version='1.0' encoding='utf-8'?>"+"<name>"+name+"</name>");
//可以直接输入地址:http://localhost:8080/tets/send?name=qq
//然后直接使用这个url地址就可以得到xml形式的输出
//<?xml version="1.0" encoding="utf-8"?><name>qq</name>
//json的你就该下格式就行了!
out.flush();
out.close();
}