这里采用的是非注解形式,相当于注解中的@responseBody
1
2
3
4
5
6
7
8
|
/** * 根据字符串输出JSON,返回null
*
* @param jsonString
* @return
*/
public String ajaxJson(HttpServletResponse response,String jsonString) { return ajax(response,jsonString, "text/html" );
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
/** * 返回json字符串(非注解形式)
* AJAX输出,返回null
*
* @param content
* @param type
* @return
*/
public String ajax(HttpServletResponse response, String content, String type) {
try {
response.setContentType(type + ";charset=UTF-8" );
response.setHeader( "Pragma" , "No-cache" );
response.setHeader( "Cache-Control" , "no-cache" );
response.setDateHeader( "Expires" , 0 );
response.getWriter().write(content);
response.getWriter().flush();
} catch (IOException e) {
e.printStackTrace();
logger.error( "IOException:" , e);
}
return null ;
}
|
本文转自建波李 51CTO博客,原文链接:http://blog.51cto.com/jianboli/1906408,如需转载请自行联系原作者