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:be.solidx.hot.test.nio.http.GetServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println(req.getContentType()); resp.getWriter().write(req.getParameter("name") + " " + req.getParameter("age")); }
From source file:X509Snoop.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); X509Certificate[] certs = (X509Certificate[]) req.getAttribute("javax.servlet.request.X509Certificate"); if (certs != null) { for (int i = 0; i < certs.length; i++) { out.println("Client Certificate [" + i + "] = " + certs[i].toString()); }//from w ww .j av a 2s .c o m } else { if ("https".equals(req.getScheme())) { out.println("This was an HTTPS request, " + "but no client certificate is available"); } else { out.println("This was not an HTTPS request, " + "so no client certificate is available"); } } }
From source file:HeaderSnoop.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); out.println("Request Headers:"); Enumeration names = req.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); Enumeration values = req.getHeaders(name); // support multiple values if (values != null) { while (values.hasMoreElements()) { String value = (String) values.nextElement(); out.println(name + ": " + value); }/* ww w . ja va 2s . c om*/ } } }
From source file:com.facebook.tsdb.tsdash.server.MetricsEndpoint.java
@Override @SuppressWarnings("unchecked") public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {/* ww w. j a va2 s . c o m*/ TsdbDataProvider dataProvider = TsdbDataProviderFactory.get(); String[] metrics = dataProvider.getMetrics(); response.setContentType("text/plain"); JSONArray encoded = new JSONArray(); for (String metric : metrics) { encoded.add(metric); } out.println(encoded.toJSONString()); } catch (Exception e) { out.println(getErrorResponse(e)); } out.close(); }
From source file:SessionTimer.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); HttpSession session = req.getSession(); out.println("<HTML><HEAD><TITLE>SessionTimer</TITLE></HEAD>"); out.println("<BODY><H1>Session Timer</H1>"); out.println("The previous timeout was " + session.getMaxInactiveInterval()); out.println("<BR>"); session.setMaxInactiveInterval(2 * 60 * 60); // two hours out.println("The newly assigned timeout is " + session.getMaxInactiveInterval()); out.println("</BODY></HTML>"); }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); out.println("Query String:"); out.println(req.getQueryString());/*from www . j a v a 2 s.com*/ out.println(); out.println("Request Parameters:"); Enumeration e = req.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); String values[] = req.getParameterValues(name); if (values != null) { for (int i = 0; i < values.length; i++) { out.println(name + " (" + i + "): " + values[i]); } } } }
From source file:com.job.portal.servlets.ProfileServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); JSONObject obj = null;// w w w . j av a2 s . c o m JSONArray arr = null; try { String param = request.getParameter("param"); HttpSession sess = request.getSession(false); UserDetails ud = (UserDetails) sess.getAttribute("user"); if (param != null) { if (param.equalsIgnoreCase("getProfile")) { } else if (param.equalsIgnoreCase("getPostedJobs")) { } } } catch (Exception e) { LogOut.log.error("In " + new Object() { }.getClass().getEnclosingClass().getName() + "." + new Object() { }.getClass().getEnclosingMethod().getName() + " " + e); } finally { out.close(); } }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); // Get the current session object, create one if necessary HttpSession session = req.getSession(); // Add a CustomBindingListener session.setAttribute("bindings.listener", new CustomBindingListener(getServletContext())); out.println("This page intentionally left blank"); }
From source file:InitParamServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); String url = getInitParameter("URL"); ServletConfig config = getServletConfig(); ServletContext context = getServletContext(); String uid = config.getInitParameter("UID"); String pwd = config.getInitParameter("PWD"); String port = context.getInitParameter("some-port"); out.println("Values retrieved for the init parameters are: "); out.println("URL: " + url); out.println("UID: " + uid); out.println("PWD: " + pwd); out.println("some-port: " + port); }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); // Get the current session object, create one if necessary HttpSession session = req.getSession(); out.println("<HTML><HEAD><TITLE>SessionTimer</TITLE></HEAD>"); out.println("<BODY><H1>Session Timer</H1>"); // Display the previous timeout out.println("The previous timeout was " + session.getMaxInactiveInterval()); out.println("<BR>"); // Set the new timeout session.setMaxInactiveInterval(2 * 60 * 60); // two hours // Display the new timeout out.println("The newly assigned timeout is " + session.getMaxInactiveInterval()); out.println("</BODY></HTML>"); }