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:MyServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>"); out.println("A Web Page"); out.println("</TITLE>"); out.println("</HEAD>"); out.println("Hello there!"); out.println("</BODY>"); out.println("</HTML>"); }
From source file:com.javiermoreno.springboot.mvc.minimal.httpd.PingController.java
@RequestMapping(value = "/long", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK)/* w w w .j a va 2 s. c o m*/ void longPing(HttpServletResponse response) throws IOException, InterruptedException { response.setBufferSize(0); PrintWriter out = response.getWriter(); out.println(); out.flush(); for (int i = 0; i < 60 * 5; i++) { out.format("Current server time: %s.\r\n", new Date()); out.flush(); Thread.sleep(1000); } }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); HttpSession session = req.getSession(); Integer count = (Integer) session.getAttribute("tracker.count"); if (count == null) count = new Integer(1); else// w w w .ja v a 2 s. c o m count = new Integer(count.intValue() + 1); session.setAttribute("tracker.count", count); out.println("<HTML><HEAD><TITLE>SessionTracker</TITLE></HEAD>"); out.println("<BODY><H1>Session Tracking Demo</H1>"); out.println("You've visited this page " + count + ((count.intValue() == 1) ? " time." : " times.")); out.println("<P>"); out.println("<H2>Here is your session data:</H2>"); Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println(name + ": " + session.getAttribute(name) + "<BR>"); } out.println("</BODY></HTML>"); }
From source file:org.branch.annotation.audio.web.controller.UploadServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/* www. jav a 2s . c om*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @RequestMapping(method = RequestMethod.POST) protected void post(HttpServletRequest request, HttpServletResponse response) throws Exception { final PrintWriter writer = response.getWriter(); final InputStream inputStream = request.getInputStream(); final String originalFilename = request.getHeader("X-File-Name"); final Map<String, String> metadata = new HashMap<String, String>(); metadata.put("originalFilename", originalFilename); fileUploadProcessor.uploadFile(metadata, inputStream); writer.print("{success: true}"); }
From source file:org.chtijbug.drools.platform.web.security.Http200LogoutSuccessHandler.java
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { response.setStatus(SC_OK);//w ww .j a v a 2s. co m response.getWriter().write("Logged out"); }
From source file:MyServlet.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; codeObj = req.getAttribute("javax.servlet.error.status_code"); messageObj = req.getAttribute("javax.servlet.error.message"); typeObj = req.getAttribute("javax.servlet.error.exception_type"); if (codeObj != null) code = codeObj.toString();// w w w. jav a 2s .co m if (messageObj != null) message = messageObj.toString(); if (typeObj != null) type = typeObj.toString(); 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:SessionTracker.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); HttpSession session = req.getSession(true); Integer count = (Integer) session.getAttribute("count"); if (count == null) { count = new Integer(1); } else {//from w w w . ja va2 s .c o m count = new Integer(count.intValue() + 1); } session.setAttribute("count", count); out.println("<html><head><title>SessionSnoop</title></head>"); out.println("<body><h1>Session Details</h1>"); out.println( "You've visited this page " + count + ((count.intValue() == 1) ? " time." : " times.") + "<br/>"); out.println("<h3>Details of this session:</h3>"); out.println("Session id: " + session.getId() + "<br/>"); out.println("New session: " + session.isNew() + "<br/>"); out.println("Timeout: " + session.getMaxInactiveInterval() + "<br/>"); out.println("Creation time: " + new Date(session.getCreationTime()) + "<br/>"); out.println("Last access time: " + new Date(session.getLastAccessedTime()) + "<br/>"); out.println("</body></html>"); }
From source file:com.rampukar.controller.FileUploadHandler.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); //process only if its multipart content if (ServletFileUpload.isMultipartContent(request)) { try {/*from w w w . j a v a 2 s. c o m*/ List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { String name = new File(item.getName()).getName(); item.write(new File(UPLOAD_DIRECTORY + File.separator + name)); out.print(name); } } //File uploaded successfully request.setAttribute("message", "File Uploaded Successfully"); } catch (Exception ex) { request.setAttribute("message", "File Upload Failed due to " + ex); } } else { // request.setAttribute("message", "Sorry this Servlet only handles file upload request"); } // request.getRequestDispatcher("/result.jsp").forward(request, response); }
From source file:UnknownEncodingServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html; charset=ISO-8850-1"); PrintWriter out = response.getWriter(); }
From source file:com.company.project.web.controller.service.HttpLogoutSuccessHandler.java
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { response.setStatus(HttpServletResponse.SC_OK); response.getWriter().flush(); }