List of usage examples for javax.servlet.http HttpServletResponse setContentType
public void setContentType(String type);
From source file:org.slc.sli.dashboard.web.controller.MiscellaneousController.java
@RequestMapping(value = "/s/m/footer", method = RequestMethod.GET) @ResponseBody/*from w w w .j a v a2 s . co m*/ public String getFooter(HttpServletResponse response) { boolean isAdmin = SecurityUtil.isAdmin(); response.setContentType("text/html"); return portalWSManager.getFooter(isAdmin); }
From source file:com.gae.UserAdminServlet.java
@Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); resp.setCharacterEncoding("utf-8"); //PrintWriter out = resp.getWriter(); String userid = req.getParameter("userid"); String passwd = req.getParameter("passwd"); String rv = ""; try {//from w ww.j ava2 s.c o m Entity useradmin = ds.get(KeyFactory.createKey("useradmin", userid)); //1 String passwd2 = useradmin.getProperty("passwd").toString(); //2 String uclass = useradmin.getProperty("uclass").toString(); if (passwd.equals(passwd2)) { Entity userdirec = ds.get(KeyFactory.createKey("userdirec", uclass)); //1 String udirec = userdirec.getProperty("udirec").toString(); rv = "{\"status\": \"" + "OK" + "\", \"udirec\": \"" + udirec + "\"}"; } else { //rv = "????????????"; //rv = "{\"status\": \"" + "NO" + "\", \"reason\": \"" + "????????????" + "\"}"; rv = "{\"status\": \"" + "NO" + "\", \"comment\": \"????????????\"}"; } } catch (EntityNotFoundException e) { //rv = "Error = " + e; rv = "{\"status\": \"" + "NO" + "\", \"comment\": \"" + e + "\"}"; } catch (Exception e) { //rv = "Error = " + e; rv = "{\"status\": \"" + "NO" + "\", \"comment\": \"" + e + "\"}"; } //out.println(rv); resp.getWriter().println(rv); }
From source file:eu.delving.services.controller.SearchApiController.java
@RequestMapping("/api/open-search") public void openSearchServiceController(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.getWriter()/* w ww.ja va2s.c om*/ .write(OpenSearchService.parseHttpServletRequest(request, beanQueryModelFactory, launchProperties)); response.getWriter().close(); }
From source file:eu.delving.services.controller.SearchApiController.java
@RequestMapping("/api/open-search.xml") public void openSearchServiceDescriptionController(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(/*from www. j a v a 2 s . co m*/ OpenSearchService.renderDescriptionDocument(request, beanQueryModelFactory, launchProperties)); response.getWriter().close(); }
From source file:org.reallysqs.server.views.QueueListView.java
@SuppressWarnings("unchecked") @Override// w w w .j av a 2s . c o m protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/xml"); Map<String, Queue> queues = (Map<String, Queue>) model.get("queues"); Collection<Queue> queueList = queues.values(); ServletOutputStream outputStream = response.getOutputStream(); outputStream.print(prelude); for (Queue queue : queueList) { outputStream.print("<QueueUrl>"); outputStream.print("http://" + request.getLocalName() + ":" + request.getLocalPort() + request.getContextPath() + request.getServletPath() + "/queues/" + queue.getName()); outputStream.print("</QueueUrl>"); } outputStream.print(epilogue); }
From source file:com.kelveden.rastajax.servlet.DefaultJsonServlet.java
private void writeRepresentationToResponse(JsonNode representation, HttpServletResponse httpResponse) throws IOException { httpResponse.setContentType("application/json; charset=utf8"); final OutputStream outputStream = httpResponse.getOutputStream(); outputStream.write(representation.toString().getBytes("UTF-8")); outputStream.flush();//www . j av a2 s . c om }
From source file:it.drwolf.ridire.servlet.TmpResourcesServlet.java
public void getTmpFile(String filename) { HttpServletResponse response = (HttpServletResponse) this.extCtx.getResponse(); response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); try {//from w w w.j a va 2s .com String ret = FileUtils.readFileToString( new File( System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + filename), "UTF-8"); response.getOutputStream().print(ret); response.getOutputStream().flush(); // FacesContext.getCurrentInstance().responseComplete(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:SessionDisplay.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); HttpSession session = request.getSession(); Date creationTime = new Date(session.getCreationTime()); Date lastAccessed = new Date(session.getLastAccessedTime()); Date now = new Date(); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); out.println("<html>"); out.println("<head>"); out.println("<title>Displaying the Session Creation and Last-Accessed Time</title>"); out.println("</head>"); out.println("<body>"); out.println("<h2>Session Creation and Last-Accessed Time</h2>"); out.println("The time and date now is: " + formatter.format(now) + "<br><br>"); out.println("The session creation time: HttpSession.getCreationTime( ): " + formatter.format(creationTime) + "<br><br>"); out.println("The last time the session was accessed: HttpSession.getLastAccessedTime( ): " + formatter.format(lastAccessed)); out.println("</body>"); out.println("</html>"); }
From source file:org.openmrs.module.radiology.web.controller.maintainer.MaintainController.java
/** * Accept a test/* w w w.j ava2s. c o m*/ * * @param orderId * @param model * @return id of accepted radiology test * @throws IOException */ @RequestMapping(value = "/module/radiology/maintain/checkRadiologyForm.htm", method = RequestMethod.GET) public void checkRadiology(HttpServletResponse response) throws IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter writer = response.getWriter(); Pattern pattern = Pattern.compile("name=\"[a-zA-Z0-9 ]*\""); List<RadiologyForm> forms = Context.getService(RadiologyService.class).getAllRadiologyForms(); Set<String> invalidConcepts = new HashSet<String>(); Set<Integer> formIds = new HashSet<Integer>(); for (RadiologyForm form : forms) { Matcher matcher = pattern.matcher(form.getContent()); while (matcher.find()) { String name = matcher.group().substring(6, matcher.group().length() - 1); Concept concept = Context.getConceptService().getConcept(name); if (concept == null) { invalidConcepts.add(name); formIds.add(form.getId()); } } } writer.println(formIds); for (String name : invalidConcepts) { writer.println(name); } }
From source file:io.hawt.testing.env.builtin.NotFound.java
@Override public void handle(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); resp.setContentType("application/json"); resp.setCharacterEncoding("UTF-8"); JSONObject r = new JSONObject(); r.put("error", HttpServletResponse.SC_NOT_FOUND); r.put("message", "Environment not found"); resp.getWriter().println(r.toJSONString()); resp.getWriter().close();/*ww w . ja v a 2s.c o m*/ }