public class TestOutHTML extends HttpServlet{ private static ThreadLocal tLocal = null; @Override public void init() throws ServletException { tLocal = new ThreadLocal(); } public final void outHTML(String strHTML){ try { HttpServletResponse response = (HttpServletResponse) tLocal.get(); byte[] buffer = strHTML.getBytes(); response.setContentType("text/html"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0L); response.setContentLength(strHTML.length()); response.getOutputStream().write(buffer); response.getOutputStream().flush(); } catch (Exception e) { e.printStackTrace(); } }}