用ajax java后台传回值,包括传json
public static final void sendAsJson(HttpServletResponse response, String str)
{
response.setContentType("application/json;charset=UTF-8");
if (null != str)
try {
response.getWriter().write(str);
} catch (IOException e) {
e.printStackTrace();
}
}
public static final void sendAsText(HttpServletResponse response, String str)
{
response.setContentType("text/html;charset=UTF-8");
if (null != str)
try {
response.getWriter().write(str);
} catch (IOException e) {
e.printStackTrace();
}
}
本文介绍了一个简单的Java方法,用于将字符串作为JSON或纯文本通过HTTP响应返回。这通常用于AJAX请求的后端处理,可以方便地实现前后端的数据交互。
1233

被折叠的 条评论
为什么被折叠?



