Java examples for javax.servlet.http:HttpServletResponse
do Ajax Json to HttpServletResponse
import java.io.IOException; import java.io.UnsupportedEncodingException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Main{ /*ww w. j av a2 s .c o m*/ public static void doAjaxJson(String json, HttpServletResponse response) throws IOException { response.setContentType("application/json;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); if (json != null && json.length() > 0) { response.getWriter().write(json); response.getWriter().flush(); } } public static void doAjaxJson(Object obj, HttpServletResponse response) throws IOException { String json = JsonUtils.toJSONString(obj, "yyyy-MM-dd hh:mm:ss"); doAjaxJson(json, response); } }