Java examples for Servlet JSP:Servlet
output Json from HttpServletResponse
import org.apache.log4j.Logger; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.util.HashMap; import java.util.Set; public class Main{ private static final Logger logs = Logger.getLogger(ResponseUtil.class); public static void outJson(HttpServletResponse response, String json) { response.setHeader("Cache-Control", "no-cache"); response.setContentType("application/json;charset=UTF-8"); try {// www .j a va 2 s . com logs.debug(json); response.getWriter().write(json); response.getWriter().flush(); response.getWriter().close(); } catch (IOException e) { e.printStackTrace(); } } }