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("<BODY"); Cookie[] cookies = request.getCookies(); boolean foundCookie = false; for (int i = 0; i < cookies.length; i++) { Cookie cookie1 = cookies[i];/*from w w w . j a v a 2 s .c o m*/ if (cookie1.getName().equals("color")) { out.println("bgcolor = " + cookie1.getValue()); foundCookie = true; } } if (!foundCookie) { Cookie cookie1 = new Cookie("color", "cyan"); cookie1.setMaxAge(24 * 60 * 60); response.addCookie(cookie1); } out.println(">"); out.println("<H1>Setting and Reading Cookies</H1>"); out.println("This page will set its background color using a cookie when reloaded."); out.println("</BODY>"); out.println("</HTML>"); }
From source file:com.ibm.util.merge.web.InitializeServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { res.getWriter().write("Initialized"); }
From source file:tomekkup.helenos.security.web.authentication.AbstractJsonAuthenticationHandler.java
protected final void writeResult(HttpServletResponse response, Authentication authentication) throws IOException { response.setHeader("Content-Type", "application/json"); PrintWriter writer = response.getWriter(); objectMapper.writeValue(writer, (authentication != null ? authentication.getAuthorities() : null)); writer.flush();// w w w . j av a 2 s . c om }
From source file:edu.lafayette.metadb.web.permission.ShowProjectPermission.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) *//*from ww w. j av a2 s. c o m*/ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub PrintWriter out = response.getWriter(); String userName = request.getParameter("username"); List<String> projectList = ProjectsDAO.getProjectList(); JSONArray list = new JSONArray(); // String bigList = ""; ArrayList<Permission> permissionList = PermissionManDAO.getAllProjectPermission(userName); if (permissionList != null && !permissionList.isEmpty()) for (Permission p : permissionList) projectList.remove(p.getProjectName()); for (String s : projectList) list.put(s); // bigList += "<option name='" + s + "'>" + s + "</option>"; out.print(list); out.flush(); }
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.easyj.rest.view.EasyView.java
protected void writeResponse(HttpServletResponse response, String content) throws IOException { response.getWriter().print(content); }
From source file:com.paperfood.controller.RegisterUser.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response)/*from w ww . j a v a 2 s . c o m*/ */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); JSONObject resp = new JSONObject(); MD5Hash md5; String status = ""; try { md5 = new MD5Hash(); PaperFoodUser user = new PaperFoodUser(); user.setFirstName(request.getParameter("txtFname")); user.setLastName(request.getParameter("txtLname")); user.setEmail(request.getParameter("txtEmail")); user.setPassword(md5.getStringHash(request.getParameter("txtPass"))); DatabaseManager dm = new DatabaseManager(); dm.open(); if (dm.isUserMailExist(user.getEmail())) status = "invalid"; else { dm.insertUser(user); status = "success"; } dm.close(); } catch (Exception e) { status = "fail"; e.printStackTrace(); } try { resp.put("status", status); } catch (JSONException e) { e.printStackTrace(); } response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); out.println(resp); }
From source file:Properties.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter out = resp.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>My First Servlet</title>"); out.println("</head>"); out.println("<h2><center>"); out.println("Information About You</center></h2>"); out.println("<br>"); out.println("<center><table border>"); out.println("<tr>"); out.println("<td>Method</td>"); out.println("<td>" + req.getMethod() + "</td>"); out.println("</tr>"); out.println("<tr>"); out.println("<td>User</td>"); out.println("<td>" + req.getRemoteUser() + "</td>"); out.println("</tr>"); out.println("<tr>"); out.println("<td>Client</td>"); out.println("<td>" + req.getRemoteHost() + "</td>"); out.println("</tr>"); out.println("<tr>"); out.println("<td>Protocol</td>"); out.println("<td>" + req.getProtocol() + "</td>"); out.println("</tr>"); java.util.Enumeration e = req.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println("<tr>"); out.println("<td>Parameter '" + name + "'</td>"); out.println("<td>" + req.getParameter(name) + "</td>"); out.println("</tr>"); }//from w w w . ja v a 2s.com out.println("</table></center><br><hr><br>"); out.println("<h2><center>"); out.println("Server Properties</center></h2>"); out.println("<br>"); out.println("<center><table border width=80%>"); java.util.Properties props = System.getProperties(); e = props.propertyNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println("<tr>"); out.println("<td>" + name + "</td>"); out.println("<td>" + props.getProperty(name) + "</td>"); out.println("</tr>"); } out.println("</table></center>"); out.println("</html>"); out.flush(); }
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("snoop.count"); if (count == null) count = new Integer(1); else/*www.j av a2 s . c o m*/ count = new Integer(count.intValue() + 1); session.setAttribute("snoop.count", count); out.println("<HTML><HEAD><TITLE>SessionSnoop</TITLE></HEAD>"); out.println("<BODY><H1>Session Snoop</H1>"); out.println("You've visited this page " + count + ((count.intValue() == 1) ? " time." : " times.")); out.println("<P>"); out.println("<H3>Here is your saved session data:</H3>"); Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println(name + ": " + session.getAttribute(name) + "<BR>"); } out.println("<H3>Here are some vital stats on your session:</H3>"); out.println("Session id: " + session.getId() + " <I>(keep it secret)</I><BR>"); out.println("New session: " + session.isNew() + "<BR>"); out.println("Timeout: " + session.getMaxInactiveInterval()); out.println("<I>(" + session.getMaxInactiveInterval() / 60 + " minutes)</I><BR>"); out.println("Creation time: " + session.getCreationTime()); out.println("<I>(" + new Date(session.getCreationTime()) + ")</I><BR>"); out.println("Last access time: " + session.getLastAccessedTime()); out.println("<I>(" + new Date(session.getLastAccessedTime()) + ")</I><BR>"); out.println("Requested session ID from cookie: " + req.isRequestedSessionIdFromCookie() + "<BR>"); out.println("Requested session ID from URL: " + req.isRequestedSessionIdFromURL() + "<BR>"); out.println("Requested session ID valid: " + req.isRequestedSessionIdValid() + "<BR>"); out.println("<H3>Test URL Rewriting</H3>"); out.println("Click <A HREF=\"" + res.encodeURL(req.getRequestURI()) + "\">here</A>"); out.println("to test that session tracking works via URL"); out.println("rewriting even when cookies aren't supported."); out.println("</BODY></HTML>"); }
From source file:cf.spring.HealthzHandlerMapping.java
public HealthzHandlerMapping(int order) { setOrder(order);/*from w w w .j av a 2 s. c o m*/ registerHandler("/healthz", new HttpRequestHandler() { @Override public void handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { httpServletResponse.setContentType("text/plain;charset=utf-8"); httpServletResponse.getWriter().write("ok"); } }); }