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/plain"); PrintWriter out = res.getWriter(); count++;/*from w ww . j a v a2 s . c o m*/ out.println("Since loading, this servlet instance has been accessed " + count + " times."); // Keep track of the instance count by putting a reference to this // instance in a Hashtable. Duplicate entries are ignored. // The size() method returns the number of unique instances stored. instances.put(this, this); out.println("There are currently " + instances.size() + " instances."); classCount++; out.println("Across all instances, this servlet class has been " + "accessed " + classCount + " times."); }
From source file:net.hillsdon.reviki.web.handlers.StreamView.java
public void render(final HttpServletRequest request, final HttpServletResponse response) throws Exception { response.setContentType(_mimeType); IOUtils.copy(_contents, response.getOutputStream()); }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); // Get the client's hostname String remoteHost = req.getRemoteHost(); out.println("remoteHost:" + remoteHost); // See if the client is allowed if (!isHostAllowed(remoteHost)) { out.println("Access <BLINK>denied</BLINK>"); } else {//w w w. j ava 2 s . c o m out.println("Access granted"); // Display download links, etc... } }
From source file:X509Snoop.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); X509Certificate[] certs = (X509Certificate[]) req.getAttribute("javax.servlet.request.X509Certificate"); if (certs != null) { for (int i = 0; i < certs.length; i++) { out.println("Client Certificate [" + i + "] = " + certs[i].toString()); }// w ww . jav a 2 s . c o m } else { if ("https".equals(req.getScheme())) { out.println("This was an HTTPS request, " + "but no client certificate is available"); } else { out.println("This was not an HTTPS request, " + "so no client certificate is available"); } } }
From source file:ExportRestriction.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); // Get the client's hostname String remoteHost = req.getRemoteHost(); // See if the client is allowed if (!isHostAllowed(remoteHost)) { out.println("Access <BLINK>denied</BLINK>"); } else {//w w w .ja va2 s . com out.println("Access granted"); // Display download links, etc... } }
From source file:HeaderSnoop.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); out.println("Request Headers:"); Enumeration names = req.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); Enumeration values = req.getHeaders(name); // support multiple values if (values != null) { while (values.hasMoreElements()) { String value = (String) values.nextElement(); out.println(name + ": " + value); }//from w w w. ja v a2 s.c o m } } }
From source file:org.vbossica.springbox.metrics.PingController.java
@RequestMapping(value = "/metrics/ping", method = RequestMethod.GET) public void process(HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store"); resp.setStatus(HttpServletResponse.SC_OK); if (message != null || message.isEmpty()) { PrintWriter writer = resp.getWriter(); try {//from ww w . jav a2 s. c om writer.println(message); } finally { writer.close(); } } }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); out.println("Query String:"); out.println(req.getQueryString());//www . j av a 2s.c om out.println(); out.println("Request Parameters:"); Enumeration e = req.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); String values[] = req.getParameterValues(name); if (values != null) { for (int i = 0; i < values.length; i++) { out.println(name + " (" + i + "): " + values[i]); } } } }
From source file:SessionTimer.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); HttpSession session = req.getSession(); out.println("<HTML><HEAD><TITLE>SessionTimer</TITLE></HEAD>"); out.println("<BODY><H1>Session Timer</H1>"); out.println("The previous timeout was " + session.getMaxInactiveInterval()); out.println("<BR>"); session.setMaxInactiveInterval(2 * 60 * 60); // two hours out.println("The newly assigned timeout is " + session.getMaxInactiveInterval()); out.println("</BODY></HTML>"); }
From source file:com.turn.splicer.ConfigServlet.java
private void doGetWork(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("application/json"); JsonGenerator generator = new JsonFactory().createGenerator(response.getOutputStream(), JsonEncoding.UTF8); Config.get().writeAsJson(generator); generator.close();/*from w w w . jav a 2 s . co m*/ }