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:TestServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . j a v a 2 s .co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet TestServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>"); out.println("</body>"); out.println("</html>"); } finally { out.close(); } }
From source file:com.mykarsol.appconnectivity.imageload.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w ww . ja v a 2s. c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ } }
From source file:com.student.manager.servlet.RegistrationServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w. ja va2 s .com*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet StudentRegistration</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet StudentRegistration at " + request.getContextPath() + "</h1>"); out.println("</body>"); out.println("</html>"); } }
From source file:org.sample.nonblocking.WriteTestServlet.java
/** * Processes requests for both HTTP/*from w ww . j a v a 2 s . c o m*/ * <code>GET</code> and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet WriteServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet WriteServlet at " + request.getContextPath() + "</h1>"); AsyncContext context = request.startAsync(); ServletOutputStream output = response.getOutputStream(); output.setWriteListener(new MyWriteListener(output, context)); out.println("</body>"); out.println("</html>"); } }
From source file:com.Accenture.Java.NewServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www .j av a 2 s. co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet NewServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>"); out.println("</body>"); out.println("</html>"); } }
From source file:com.redoute.datamap.servlet.picture.DeletePicture.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* ww w . j av a 2 s. c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); try { String name = policy.sanitize(request.getParameter("id")); ApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); IPictureService datamapService = appContext.getBean(IPictureService.class); IFactoryPicture factoryPicture = appContext.getBean(IFactoryPicture.class); Picture sqlLib = factoryPicture.create(Integer.valueOf(name), null, null, null, null); datamapService.deletePicture(sqlLib); response.sendRedirect("Datamap.jsp"); } finally { out.close(); } }
From source file:com.bluelotussoftware.apache.commons.fileupload.example.CommonsFileUploadServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); response.setContentType("text/html"); log("Content-Type: " + request.getContentType()); DiskFileItemFactory fileItemFactory = new DiskFileItemFactory(); /*/* www . j a v a 2s .c o m*/ *Set the size threshold, above which content will be stored on disk. */ fileItemFactory.setSizeThreshold(10 * 1024 * 1024); //10 MB /* * Set the temporary directory to store the uploaded files of size above threshold. */ fileItemFactory.setRepository(tmpDir); ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory); try { /* * Parse the request */ List items = uploadHandler.parseRequest(request); log("FileItems: " + items.toString()); Iterator itr = items.iterator(); while (itr.hasNext()) { FileItem item = (FileItem) itr.next(); /* * Handle Form Fields. */ if (item.isFormField()) { out.println("File Name = " + item.getFieldName() + ", Value = " + item.getString()); } else { //Handle Uploaded files. out.println("<html><head><title>CommonsFileUploadServlet</title></head><body><p>"); out.println("Field Name = " + item.getFieldName() + "\nFile Name = " + item.getName() + "\nContent type = " + item.getContentType() + "\nFile Size = " + item.getSize()); out.println("</p>"); out.println("<img src=\"" + request.getContextPath() + "/files/" + item.getName() + "\"/>"); out.println("</body></html>"); /* * Write file to the ultimate location. */ File file = new File(destinationDir, item.getName()); item.write(file); } out.close(); } } catch (FileUploadException ex) { log("Error encountered while parsing the request", ex); } catch (Exception ex) { log("Error encountered while uploading file", ex); } }
From source file:com.splout.db.examples.PageCountsTrendingServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { long now = System.currentTimeMillis(); if (cachedString != null && (now - cachedFrom) < CACHE_FOR) { resp.getWriter().write(cachedString); log.info("Returning XML content from cache."); return;// w ww . j a va 2 s .c o m } HttpRequest trendReq = requestFactory .buildGetRequest(new GenericUrl("http://www.trendingtopics.org/pages.xml?page=1")); cachedString = SploutClient.asString(trendReq.execute().getContent()); log.info("Got XML content from trendingtopics: " + cachedString); cachedFrom = System.currentTimeMillis(); resp.getWriter().write(cachedString); }
From source file:CPD4414Assign3.ProductServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { try (PrintWriter out = response.getWriter()) { Connection conn = getConnection(); Statement stmt = conn.createStatement(); if (!request.getParameterNames().hasMoreElements()) { out.println(getResults("SELECT * FROM product")); } else {//from ww w .j a v a 2s. c o m if (request.getParameter("productID") == null) { out.println(getResults("SELECT * FROM product ORDER BY productID DESC LIMIT 1")); } else { int id = Integer.parseInt(request.getParameter("productID")); out.println(getResults("SELECT * FROM product WHERE productID = ?", String.valueOf(id))); } } } catch (SQLException ex) { Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:forseti.JUploadFichero.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Forseti</title>"); out.println("</head>"); out.println("<body>"); //System.out.println("Comenzamos procesamiento ficheros"); procesaFicheros(request, out);/*w w w . ja v a 2s. c o m*/ out.println("</body>"); out.println("</html>"); out.close(); }