List of usage examples for javax.servlet.http HttpServletResponse setContentType
public void setContentType(String type);
From source file:LocaleInformationServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); Locale userPreferredLocale = request.getLocale(); Enumeration userPreferredLocales = request.getLocales(); out.println("Preferred Locale: " + userPreferredLocale.toString()); out.println(""); out.print("Preferred Locales: "); while (userPreferredLocales.hasMoreElements()) { userPreferredLocale = (Locale) userPreferredLocales.nextElement(); out.print(userPreferredLocale.toString() + ", "); }/*from w ww . ja v a2 s .c om*/ out.println(); out.println(""); }
From source file:org.openmrs.module.clinicalsummary.web.controller.watcher.CohortEvaluationWatcherController.java
@RequestMapping(method = RequestMethod.GET) public void watch(final HttpServletResponse response) throws IOException { response.setContentType(MimeType.APPLICATION_JSON); JsonFactory factory = new JsonFactory(); JsonGenerator generator = factory.createJsonGenerator(response.getOutputStream(), JsonEncoding.UTF8); generator.useDefaultPrettyPrinter(); generator.writeStartObject();// w w w. j av a 2 s .co m SummaryCohortEvaluatorInstance instanceSummary = SummaryCohortEvaluatorInstance.getInstance(); generator.writeBooleanField("running", instanceSummary.isRunning()); generator.writeStringField("filename", instanceSummary.getCurrentPatient()); generator.writeStringField("status", instanceSummary.getCurrentStatus()); generator.writeStringField("counter", instanceSummary.getProcessed()); generator.writeStringField("size", instanceSummary.getSize()); generator.writeEndObject(); generator.close(); }
From source file:org.openmrs.module.clinicalsummary.web.controller.watcher.ReminderEvaluationWatcherController.java
@RequestMapping(method = RequestMethod.GET) public void watch(final HttpServletResponse response) throws IOException { response.setContentType(MimeType.APPLICATION_JSON); JsonFactory factory = new JsonFactory(); JsonGenerator generator = factory.createJsonGenerator(response.getOutputStream(), JsonEncoding.UTF8); generator.useDefaultPrettyPrinter(); generator.writeStartObject();/*from w w w. j ava 2s. co m*/ ReminderCohortEvaluatorInstance instanceSummary = ReminderCohortEvaluatorInstance.getInstance(); generator.writeBooleanField("running", instanceSummary.isRunning()); generator.writeStringField("filename", instanceSummary.getCurrentPatient()); generator.writeStringField("status", instanceSummary.getCurrentStatus()); generator.writeStringField("counter", instanceSummary.getProcessed()); generator.writeStringField("size", instanceSummary.getSize()); generator.writeEndObject(); generator.close(); }
From source file:org.openmrs.module.clinicalsummary.web.controller.watcher.RuleEvaluationWatcherController.java
@RequestMapping(method = RequestMethod.GET) public void watch(final HttpServletResponse response) throws IOException { response.setContentType(MimeType.APPLICATION_JSON); JsonFactory factory = new JsonFactory(); JsonGenerator generator = factory.createJsonGenerator(response.getOutputStream(), JsonEncoding.UTF8); generator.useDefaultPrettyPrinter(); generator.writeStartObject();//from www . j a va 2 s . c om RuleCohortEvaluatorInstance instanceCohort = RuleCohortEvaluatorInstance.getInstance(); generator.writeBooleanField("running", instanceCohort.isRunning()); generator.writeStringField("filename", instanceCohort.getCurrentPatient()); generator.writeStringField("status", instanceCohort.getCurrentStatus()); generator.writeStringField("counter", instanceCohort.getProcessed()); generator.writeStringField("size", instanceCohort.getSize()); generator.writeEndObject(); generator.close(); }
From source file:com.skcraft.launcher.creator.server.LatestHandler.java
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/plain; charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); LatestVersionInfo info = new LatestVersionInfo(); info.setVersion("0.0.0"); info.setUrl(new URL("http://localhost")); mapper.writeValue(response.getWriter(), info); baseRequest.setHandled(true);// w ww .j a v a2 s. co m }
From source file:com.elit2.app.control.FileUpload.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("text/html"); boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { ServletFileUpload upload = new ServletFileUpload(); try {// ww w . ja va2 s. co m FileItemIterator itr = upload.getItemIterator(request); while (itr.hasNext()) { FileItemStream item = itr.next(); if (item.isFormField()) { String fieldName = item.getFieldName(); InputStream is = item.openStream(); byte[] b = new byte[is.available()]; is.read(b); String value = new String(b); response.getWriter().println(fieldName + ":" + value + "<br/>"); } else { String path = getServletContext().getRealPath("/"); if (com.elit2.app.model.FileUpload.proccessFile(path, item)) { response.getWriter().print("Deu certo"); } else { response.getWriter().print("Deu errado"); } } } } catch (FileUploadException ex) { ex.printStackTrace(); } } }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { ServletOutputStream out = res.getOutputStream(); res.setContentType("text/html"); out.println("<html><head><title>Basic Servlet</title></head>"); out.println("<body>Database username is <b>" + dbName); out.println("</b><br>Database password is <b>" + dbPassword + "</b>"); out.println("</body></html>"); }
From source file:Cookies.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); req.getSession();//from w w w . java 2 s .c o m PrintWriter out = resp.getWriter(); Cookie cookies[] = req.getCookies(); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet Cookie Information</title>"); out.println("</head>"); out.println("<body>"); if ((cookies == null) || (cookies.length == 0)) { out.println("<center><h1>No Cookies found</h1>"); } else { out.println("<center><h1>Cookies found</h1>"); out.println("<table border>"); out.println("<tr><th>Name</th><th>Value</th>" + "<th>Comment</th><th>Max Age</th></tr>"); for (int i = 0; i < cookies.length; i++) { Cookie c = cookies[i]; out.println("<tr><td>" + c.getName() + "</td><td>" + c.getValue() + "</td><td>" + c.getComment() + "</td><td>" + c.getMaxAge() + "</td></tr>"); } out.println("</table></center>"); } out.println("</body>"); out.println("</html>"); out.flush(); }
From source file:ErrorDisplay.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; // Retrieve the three possible error attributes, some may be null codeObj = req.getAttribute("javax.servlet.error.status_code"); messageObj = req.getAttribute("javax.servlet.error.message"); typeObj = req.getAttribute("javax.servlet.error.exception_type"); // Convert the attributes to string values if (codeObj != null) code = codeObj.toString();/*www . j a v a 2 s. c o m*/ if (messageObj != null) message = messageObj.toString(); if (typeObj != null) type = typeObj.toString(); // The error reason is either the status code or exception type 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:com.gu.management.spring.ManagementUrlDiscoveryController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter writer = response.getWriter(); writer.write("<html><head><title>Management URLs</title></head><body><h2>Management URLs</h2><ul>\n"); Collection<String> managementUrls = service.getManagementUrls(); for (String url : managementUrls) { if (!"/management".equals(url)) { writer.printf("<li><a href=\"management%s\">%s</a></li>\n", url, url); }/*from w w w . j a v a 2 s . com*/ } writer.write("</ul></body></html>"); return null; }