List of usage examples for javax.servlet.http HttpServletResponse getWriter
public PrintWriter getWriter() throws IOException;
PrintWriter
object that can send character text to the client. From source file:SiteSelector.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); int siteIndex = Math.abs(random.nextInt()) % sites.size(); String site = sites.elementAt(siteIndex); res.setStatus(res.SC_MOVED_TEMPORARILY); res.setHeader("Location", site); }
From source file:com.indoqa.osgi.embedded.sample.webapp.SampleServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter writer = resp.getWriter(); DateServiceProvider dateServiceProvider = this.applicationContext.getBean(DateServiceProvider.class); if (dateServiceProvider == null) { writer.write("\nCouldn't find bean of type " + DateService.class.getName()); } else {/*from www. ja v a 2 s.c om*/ DateService[] dateServices = dateServiceProvider.getDateServices(); writer.write("\nFound " + dateServices.length + " date service instance(s)."); for (DateService eachDateService : dateServices) { writer.write("\n* DateService output: " + eachDateService.getDate()); } } }
From source file:org.cloudfoundry.samples.handson.ex4.EnvVariablesController.java
/** * Use the out variable to dump the contents of the environment variables. * //from w w w .j a v a 2 s .c o m * Notice how CloudFoundry instructs the app about services it provides * inside variables named {@code VCAP_something}. */ @RequestMapping("/ex4") public void dump(HttpServletResponse response) throws Exception { @SuppressWarnings("unused") PrintWriter out = response.getWriter(); Map<String, String> env = System.getenv(); for (Entry<String, String> envi : env.entrySet()) { out.write(envi.getKey() + " => " + envi.getValue() + "\n"); } // ... }
From source file:com.xqdev.jam.MLJAM.java
private static void sendServerProblemResponse(HttpServletResponse res, String s) throws IOException { // Commenting out the status code because we want the client to eval the error() call //res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); res.setContentType("x-marklogic/xquery; charset=UTF-8"); if (s != null && s.length() > 4096) { // Cap super long errors s = s.substring(0, 2048) + " ...[trimmed]... " + s.substring(s.length() - 2048); }/* w w w.j ava 2s . co m*/ Writer writer = res.getWriter(); writer.write("error('" + escapeSingleQuotes(s) + "')"); writer.flush(); }
From source file:AuthenticationSnoop.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<HTML><BODY>"); out.println("<H1>This is a password protected resource</H1>"); out.println("<PRE>"); out.println("User Name: " + req.getRemoteUser()); String name = (req.getUserPrincipal() == null) ? null : req.getUserPrincipal().getName(); out.println("Principal Name: " + name); out.println("Authentication Type: " + req.getAuthType()); out.println("Is a Manager: " + req.isUserInRole("manager")); out.println("</PRE>"); out.println("</BODY></HTML>"); }
From source file:localdomain.localhost.JclDemoServlet.java
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter writer = resp.getWriter(); writer.println("<html>"); writer.println("<head><title>Jakarta Commons Logging Demo Servlet</title></head>"); writer.println("<body><h1>Jakarta Commons Logging Demo Servlet</h1>"); writer.println("<h2>JCL messages</h2>"); writer.println(// w w w .j av a 2 s .co m "<p>Output TRACE, DEBUG, INFO, WARN, ERROR, FATAL messages to commons-logging logger " + logger); logger.trace("Trace message"); logger.debug("Debug message"); logger.info("Info message"); logger.warn("Warn message"); logger.error("Error message"); logger.fatal("Fatal message"); writer.println("</body></html>"); }
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("Request Headers:"); out.println();/*ww w . j av a 2 s . c o m*/ 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 source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); count++;/* w w w .j a va2s.c om*/ 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: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 {/*ww w.j a v a2 s . c o m*/ out.println("Access granted"); // Display download links, etc... } }
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 {//www . j ava2s.co m out.println("Access granted"); // Display download links, etc... } }