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 req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); // Ask for a 16K byte response buffer; do not set the content length res.setBufferSize(16 * 1024);/*from w ww . jav a 2 s .c om*/ PrintWriter out = res.getWriter(); out.println("<HTML>"); out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>"); out.println("<BODY>"); out.println("<BIG>Less than 16K of response body</BIG>"); out.println("</BODY></HTML>"); }
From source file:com.sentinel.rest.handlers.HttpLogoutSuccessHandler.java
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { LOG.trace("Method: onLogoutSuccess called."); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().flush(); LOG.trace("Method: onLogoutSuccess finished."); }
From source file:workspace.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request// ww w . j av a2s. c om * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); String class1 = request.getParameter("class"); String hour = request.getParameter("hour"); HttpSession session = request.getSession(false); if (session == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); } else { if (hour == null) { try { current(out, class1); } catch (Exception e) { } } else { try { importlast(out, class1, hour); } catch (Exception e) { } } } }
From source file:edu.lafayette.metadb.web.authentication.CheckSession.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */// w w w . ja v a 2 s. co m protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub PrintWriter out = response.getWriter(); JSONObject output = new JSONObject(); try { HttpSession session = request.getSession(false); if (session != null && checkUser(session)) { String name = (String) session.getAttribute(Global.SESSION_USERNAME); User user = UserManDAO.getUserData(name); long last_login = ((Long) session.getAttribute(Global.SESSION_LOGIN_TIME)).longValue(); Date date = new Date(last_login + 5 * 3600 * 1000); output.put("username", name); output.put("admin", user.getType().equals(Global.USER_ADMIN)); output.put("local", user.getAuthType().equals("Local")); output.put("last_login", date.toString()); output.put("success", true); output.put("parser_running", MetaDbHelper.getParserStatus()); output.put("record_count", MetaDbHelper.getItemCount()); output.put("log_types", Global.eventTypes); String[] last_page = UserManDAO.getLastProj(name).split(";"); if (last_page.length > 1) { output.put("last_proj", last_page[0]); output.put("last_item", last_page[1]); } } else { output.put("success", false); output.put("message", "Your session has expired"); } out.print(output); } catch (Exception e) { MetaDbHelper.logEvent(e); } response.setContentType("application/x-json"); out.flush(); }
From source file:AllEmployeesServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>All Employees</title></head>"); out.println("<body>"); out.println("<center><h1>All Employees</h1>"); Connection conn = null;/*from ww w .j a va2s .c o m*/ Statement stmt = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("jdbc:odbc:Employees"); stmt = conn.createStatement(); String orderBy = request.getParameter("sort"); if ((orderBy == null) || orderBy.equals("")) { orderBy = "SSN"; } String orderByDir = request.getParameter("sortdir"); if ((orderByDir == null) || orderByDir.equals("")) { orderByDir = "asc"; } String query = "SELECT Employees.SSN, Employees.Name, " + "Employees.Salary, " + "Employees.Hiredate, Location.Location " + "FROM Location " + "INNER JOIN Employees " + "ON Location.Loc_Id = Employees.Loc_Id " + "ORDER BY " + orderBy + " " + orderByDir + ";"; ResultSet rs = stmt.executeQuery(query); while (rs.next()) { long employeeSSN = rs.getLong("SSN"); String employeeName = rs.getString("Name"); long employeeSalary = rs.getLong("Salary"); Date employeeHiredate = rs.getDate("Hiredate"); String employeeLocation = rs.getString("Location"); out.print(employeeSSN + "::"); out.print(employeeName + "::"); out.print(employeeSalary + "::"); out.print(employeeHiredate + "::"); out.print(employeeLocation + "::"); } } catch (SQLException e) { out.println("An error occured while retrieving " + "all employees: " + e.toString()); } catch (ClassNotFoundException e) { throw (new ServletException(e.toString())); } finally { try { if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (SQLException ex) { } } out.println("</center>"); out.println("</body>"); out.println("</html>"); out.close(); }
From source file:com.redoute.datamap.servlet.datamap.UpdateDatamap.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w . j a v a 2 s .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"); PrintWriter out = response.getWriter(); PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); try { String name = policy.sanitize(request.getParameter("id")); String columnName = policy.sanitize(request.getParameter("columnName")); String value = policy.sanitize(request.getParameter("value")); ApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); IDatamapService datamapService = appContext.getBean(IDatamapService.class); datamapService.updateDatamap(name, columnName, value); out.print(value); } finally { out.close(); } }
From source file:com.redoute.datamap.servlet.picture.UpdatePicture.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . j ava 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(); PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); try { String name = policy.sanitize(request.getParameter("id")); String columnName = policy.sanitize(request.getParameter("columnName")); String value = policy.sanitize(request.getParameter("value")); ApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); IPictureService datamapService = appContext.getBean(IPictureService.class); datamapService.updatePicture(name, columnName, value); out.print(value); } finally { out.close(); } }
From source file:geo.controller.LoadMRTServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . ja v a 2 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("application/json"); PrintWriter out = response.getWriter(); try { ArrayList<MRTStation> mrtList = MRTStationDAO.getMRTList(); JSONArray jsonArray = new JSONArray(); int index = 0; for (int i = 0; i < mrtList.size(); i++) { if (mrtList.get(i).lat == 0 && mrtList.get(i).lng == 0) { continue; } jsonArray.add(index++, mrtList.get(i).getJSONObject()); } out.println(jsonArray.toJSONString()); } catch (Exception e) { e.printStackTrace(); } finally { out.close(); } }
From source file:de.knightsoftnet.validators.server.security.AuthFailureHandler.java
@Override public void onAuthenticationFailure(final HttpServletRequest prequest, final HttpServletResponse presponse, final AuthenticationException pexception) throws IOException, ServletException { presponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); final PrintWriter writer = presponse.getWriter(); writer.write(pexception.getMessage()); writer.flush();/* w w w . j av a 2 s . co m*/ }
From source file:net.proest.librepilot.web.handler.ObjectHandler.java
public void handlePost(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); BufferedReader br = request.getReader(); String json = ""; while (br.ready()) { json += br.readLine();// w w w .j a v a2 s . c o m } System.out.println(json); json = json.replaceFirst("json=", ""); System.out.println(json); json = URLDecoder.decode(json, "utf-8"); System.out.println(json); System.out.println(); ObjectMapper mapper = new ObjectMapper(); JsonNode actualObj = mapper.readTree(json); out.println(actualObj.asText()); out.println(mapper.toString()); }