First of all to get HttpServletResponse object in struts2 How to get here is not detailed said there are several ways not to own Baidu
I use it here.
HttpServletResponse response = (httpservletresponse) actioncontext.getcontext (). Get (Servletactioncontext.http_ RESPONSE);
The following two sentences are key. The first sentence is not likely to cause the front end to be unrecognized
The second sentence is not likely to be garbled.
Response.setcontenttype ("Text/json");
Response.setcharacterencoding ("Utf-8");
try {
out = Response.getwriter ();
} catch (IOException e) {
E.printstacktrace ();
}
Getbookinfobypagenum Gbip = new Getbookinfobypagenum ();
list<bookinfo> Bookinfos = gbip.getbypage (page, anywords);
This way, I'm using Fastjson. Convert data from list to JSON
Out.print ((Json.tojsonstring (Bookinfos, True)));
STRUTS2 return JSON-formatted data without plugins