List of usage examples for javax.servlet.http HttpServletResponse setContentType
public void setContentType(String type);
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); String code = null, message = null, type = null; Object codeObj, messageObj, typeObj; codeObj = req.getAttribute("javax.servlet.error.status_code"); messageObj = req.getAttribute("javax.servlet.error.message"); typeObj = req.getAttribute("javax.servlet.error.exception_type"); if (codeObj != null) code = codeObj.toString();/*from w w w . j av a2 s . c o m*/ if (messageObj != null) message = messageObj.toString(); if (typeObj != null) type = typeObj.toString(); String reason = (code != null ? code : type); out.println("<HTML>"); out.println("<HEAD><TITLE>" + reason + ": " + message + "</TITLE></HEAD>"); out.println("<BODY>"); out.println("<H1>" + reason + "</H1>"); out.println("<H2>" + message + "</H2>"); out.println("<HR>"); out.println("<I>Error accessing " + req.getRequestURI() + "</I>"); out.println("</BODY></HTML>"); }
From source file:SessionTracker.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); HttpSession session = req.getSession(true); Integer count = (Integer) session.getAttribute("count"); if (count == null) { count = new Integer(1); } else {//ww w .ja v a 2s. c o m count = new Integer(count.intValue() + 1); } session.setAttribute("count", count); out.println("<html><head><title>SessionSnoop</title></head>"); out.println("<body><h1>Session Details</h1>"); out.println( "You've visited this page " + count + ((count.intValue() == 1) ? " time." : " times.") + "<br/>"); out.println("<h3>Details of this session:</h3>"); out.println("Session id: " + session.getId() + "<br/>"); out.println("New session: " + session.isNew() + "<br/>"); out.println("Timeout: " + session.getMaxInactiveInterval() + "<br/>"); out.println("Creation time: " + new Date(session.getCreationTime()) + "<br/>"); out.println("Last access time: " + new Date(session.getLastAccessedTime()) + "<br/>"); out.println("</body></html>"); }
From source file:MyServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>"); out.println("Using the init Method"); out.println("</TITLE>"); out.println("</HEAD>"); out.println("<BODY>"); out.println("<H1>Using the init Method</H1>"); out.println(msg);//from w w w .j av a2 s . c om out.println("</BODY>"); out.println("</HTML>"); }
From source file:com.github.dbourdette.glass.web.controller.FilesController.java
@RequestMapping("/css/style.css") public void ccs(HttpServletResponse response) throws IOException { response.setContentType("text/css"); serveResource("/com/github/dbourdette/glass/css/style.css", response); }
From source file:com.github.dbourdette.glass.web.controller.FilesController.java
@RequestMapping("/image/{name}.png") public void image(@PathVariable String name, HttpServletResponse response) throws IOException { response.setContentType("image/png"); serveResource("/com/github/dbourdette/glass/image/" + name + ".png", response); }
From source file:com.github.dbourdette.glass.web.controller.FilesController.java
@RequestMapping("/js/{name}.js") public void javascript(@PathVariable String name, HttpServletResponse response) throws IOException { response.setContentType("application/javascript"); serveResource("/com/github/dbourdette/glass/js/" + name + ".js", response); }
From source file:org.vbossica.springbox.metrics.ThreadDumpController.java
@RequestMapping(value = "/metrics/threaddump", method = RequestMethod.GET) protected void doGet(HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/plain"); resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store"); resp.setStatus(HttpServletResponse.SC_OK); OutputStream output = resp.getOutputStream(); try {// www . j a v a 2s . c o m threadDump.dump(output); } finally { output.close(); } }
From source file:controllers.FreeOptionController.java
@RequestMapping("/getXls") public void getXls(Map<String, Object> model, HttpServletResponse response) throws Exception { response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=Options.xls"); freeOptionService.getXls().write(response.getOutputStream()); }
From source file:nl.edia.sakai.tool.skinmanager.download.SkinDownloadView.java
/** * @param response// w ww .j a v a 2s. c o m * @param myName */ protected void setHeaders(HttpServletResponse response, String myName) { response.setContentType(getContentType()); response.setHeader("Content-Disposition", "attachment; filename=" + myName + ".zip"); }
From source file:com.msopentech.odatajclient.testauthproxy.staticmetadata.StaticMetadataServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("application/xml;charset=UTF-8"); resp.getWriter().write(IOUtils.toString(getClass().getResourceAsStream("/static-metadata.xml"), "UTF-8")); }