List of usage examples for javax.servlet.http HttpServletResponse setContentType
public void setContentType(String type);
From source file:be.solidx.hot.test.nio.http.EchoPOSTServlet.java
protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws ServletException, IOException { resp.setContentType(req.getContentType()); resp.setContentLength(req.getContentLength()); String body = IOUtils.toString(req.getInputStream()); System.out.println(body);//from w w w . j ava 2 s. c o m resp.getWriter().write(body); }
From source file:com.nzion.web.PdfServlet.java
@Override protected void service(HttpServletRequest reqqest, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/plm"); response.setHeader("Content-Disposition", "attachment; filename=2D.plm"); ServletOutputStream outputStream = response.getOutputStream(); BufferedInputStream bufferedInputStream = new BufferedInputStream( new FileInputStream(new File("F:\\PDF_Stamping\\2D\\2D.zip"))); IOUtils.copy(bufferedInputStream, outputStream); bufferedInputStream.close();/*from w w w . jav a2s. c o m*/ outputStream.flush(); }
From source file:fr.penet.servlet.TitleStatsServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); String shardsString = req.getParameter("shards"); if (!StringUtils.isNumeric(shardsString)) { resp.getWriter().println("Error : empty shards parameter or not an integer"); return;//from w ww .ja va 2 s .c o m } int shards = Integer.parseInt(shardsString); String runIdString = req.getParameter("runId"); if (!StringUtils.isNumeric(runIdString)) { resp.getWriter().println("Error : empty runId parameter or not an integer"); return; } int runId = Integer.parseInt(runIdString); String runType = req.getParameter("type"); CrawlDbInput input = new CrawlDbInput(runId, shards); TitleWordsMapper mapper = new TitleWordsMapper(); Output<Map<String, List<Integer>>, Void> output; String jobName = "MR stats for " + runId; if (StringUtils.equals(runType, "sql-output")) { output = new CrawlDbOutputWords(runId); jobName += " (SQL)"; } else { output = new CrawlDbOutputWordsDatastore(runId); jobName += " (datastore)"; } MapSpecification<CrawlPage, Map<String, List<Integer>>, Void> spec = new MapSpecification.Builder<>(input, mapper, output).setJobName(jobName).build(); // default settings should be ok MapSettings settings = new MapSettings.Builder().build(); String jobId = MapJob.start(spec, settings); resp.getWriter().println("Mapper started. Job id : " + jobId); }
From source file:ShoppingCartViewerHidden.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<HEAD><TITLE>Current Shopping Cart Items</TITLE></HEAD>"); out.println("<BODY>"); // Cart items are passed in as the item parameter. String[] items = req.getParameterValues("item"); // Print the current cart items. out.println("You currently have the following items in your cart:<BR>"); if (items == null) { out.println("<B>None</B>"); } else {//from w ww .j a v a 2s.co m out.println("<UL>"); for (int i = 0; i < items.length; i++) { out.println("<LI>" + items[i]); } out.println("</UL>"); } // Ask if the user wants to add more items or check out. // Include the current items as hidden fields so they'll be passed on. out.println("<FORM ACTION=\"/servlet/ShoppingCart\" METHOD=POST>"); if (items != null) { for (int i = 0; i < items.length; i++) { out.println("<INPUT TYPE=HIDDEN NAME=\"item\" VALUE=\"" + items[i] + "\">"); } } out.println("Would you like to<BR>"); out.println("<INPUT TYPE=SUBMIT VALUE=\" Add More Items \">"); out.println("<INPUT TYPE=SUBMIT VALUE=\" Check Out \">"); out.println("</FORM>"); out.println("</BODY></HTML>"); }
From source file:net.cristcost.study.services.ServiceHttpRequestHandler.java
@Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/plain"); PrintWriter writer = response.getWriter(); ServiceTestUtil.testSecurity(this.getClass().getSimpleName(), request, writer, authenticationManager, services);/* w ww . j a va 2 s .c o m*/ }
From source file:net.cristcost.study.services.ServiceServlet.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/plain"); PrintWriter writer = response.getWriter(); ServiceTestUtil.testSecurity(this.getClass().getSimpleName(), request, writer, authenticationManager, services);// w ww. ja v a 2 s.c o m }
From source file:org.reallysqs.server.views.ReceivedMessagesResponseView.java
@SuppressWarnings("unchecked") @Override//w w w. j ava 2 s. com protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/xml"); List<Message> messages = (List<Message>) model.get("messages"); ServletOutputStream outputStream = response.getOutputStream(); outputStream.print(prelude); if (messages != null) { for (Message message : messages) { outputStream.print("<Message><MessageId>"); outputStream.print(message.getUuid()); outputStream.print("</MessageId><MessageBody>"); outputStream.print(message.getContent()); outputStream.print("</MessageBody></Message>"); } } outputStream.print(epilogue); }
From source file:ee.ria.xroad.proxy.testsuite.testcases.ServiceReturnsFault.java
@Override public AbstractHandler getServiceHandler() { return new AbstractHandler() { @Override/* w w w . j a va 2s. c om*/ public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType(MimeTypes.TEXT_XML); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); try (FileInputStream in = new FileInputStream(QUERIES_DIR + "/fault.query")) { IOUtils.copy(in, response.getOutputStream()); } baseRequest.setHandled(true); } }; }
From source file:Controlador.ChartServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("image/png"); OutputStream outputStream = response.getOutputStream(); JFreeChart chart = null;/*from w w w. j a va2 s .co m*/ try { chart = getChart(); } catch (URISyntaxException ex) { Logger.getLogger(ChartServlet.class.getName()).log(Level.SEVERE, null, ex); } int width = 500; int height = 350; ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); }
From source file:com.suntek.gztpb.controller.ChangeContactControll.java
@RequestMapping(value = "success.htm", method = RequestMethod.POST) public @ResponseBody String saveTest(DriverChangeModel driverInfo, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); String applyNum = IdGenerator.getInstance().getBizCode("ITMS_SEQ", 5); driverInfo.setApplynum(applyNum);/* w w w. j av a2s. c o m*/ System.out.println("applyNum=" + applyNum); driverInfo.setBiztype("3001"); driverInfo.setCreatedtime(new Date()); driverInfo.setCreator("admin"); driverInfo.setSource(0); driverInfo.setSubmittime(new Date()); driverInfo.setFinish(0); try { driverChangeService.signUp(driverInfo); out.write("<script>parent.saveCallback(1,'" + applyNum + "')</script>"); } catch (Exception e) { e.printStackTrace(); out.write("<script>parent.saveCallback(0)</script>"); } return null; }