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:Servlet.AddAdminServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . 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 AddAdminServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet AddAdminServlet at " + request.getContextPath() + "</h1>"); out.println("</body>"); out.println("</html>"); } }
From source file:de.tuttas.servlets.ClientConfig.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w 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"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ Config c = Config.getInstance(); Set set = c.clientConfig.keySet(); Iterator<?> keys = set.iterator(); while (keys.hasNext()) { String key = (String) keys.next(); out.println("var " + key + "=\"" + c.clientConfig.get(key) + "\";"); } out.println("var debug=" + c.debug + ";"); out.println("var servername=\"" + request.getServerName() + "\";"); out.println("var serverport=" + request.getServerPort() + ";"); } }
From source file:edu.uci.ics.asterix.api.http.servlet.RESTAPIServlet.java
/** * Initialize the Content-Type of the response, and construct a * SessionConfig with the appropriate output writer and output-format * based on the Accept: header and other servlet parameters. *//* ww w. j a v a 2 s . co m*/ static SessionConfig initResponse(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setCharacterEncoding("utf-8"); // JSON output is the default; most generally useful for a // programmatic HTTP API OutputFormat format = OutputFormat.JSON; // First check the "output" servlet parameter. String output = request.getParameter("output"); String accept = request.getHeader("Accept"); if (output != null) { if (output.equals("CSV")) { format = OutputFormat.CSV; } else if (output.equals("ADM")) { format = OutputFormat.ADM; } } else { // Second check the Accept: HTTP header. if (accept != null) { if (accept.contains("application/x-adm")) { format = OutputFormat.ADM; } else if (accept.contains("text/csv")) { format = OutputFormat.CSV; } } } SessionConfig sessionConfig = new SessionConfig(response.getWriter(), format); // Now that format is set, output the content-type switch (format) { case ADM: response.setContentType("application/x-adm"); break; case JSON: response.setContentType("application/json"); break; case CSV: { // Check for header parameter or in Accept:. if ("present".equals(request.getParameter("header")) || (accept != null && accept.contains("header=present"))) { response.setContentType("text/csv; header=present"); sessionConfig.set(SessionConfig.FORMAT_CSV_HEADER, true); } else { response.setContentType("text/csv; header=absent"); } } } ; return sessionConfig; }
From source file:com.alzatezabala.fp.presentacion.controller.EntidadBancariaController.java
@RequestMapping(value = { "/EntidadBancaria/{id}" }, method = RequestMethod.GET) public void get(HttpServletRequest httpRequest, HttpServletResponse httpServletResponse, @PathVariable("id") int idEntidad) throws IOException { String jsonResponse = new JSONConverterImplJackson().toJSON(entidadBancariaDAO.get(idEntidad)); httpServletResponse.getWriter().println(jsonResponse); }
From source file:com.ibm.cf.ManifestController.java
@RequestMapping(value = "/download", method = RequestMethod.POST) public void download(HttpServletRequest request, HttpServletResponse response) throws IOException { Manifest manifest = new Manifest(request); response.setHeader("Content-Disposition", "attachment; filename=manifest.yml"); response.setContentType("text/plain"); response.getWriter().write(manifest.toString()); }
From source file:getDeals.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w ww.j a va 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("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); try { String url = "https://tgl.standardchartered.com/bridgeheadi18n/V6/offers/offerdetails?country=SG&lang=en&deviceId=0&offerVersion=0&couponVersion=0&categoryVersion=0"; HttpClient client = new DefaultHttpClient(); HttpGet req = new HttpGet(url); HttpResponse res = client.execute(req); BufferedReader rd = new BufferedReader(new InputStreamReader(res.getEntity().getContent())); String line = ""; String total = ""; while ((line = rd.readLine()) != null) { total += line; } total = total.substring(0, total.length()); out.println(total); } finally { out.close(); } }
From source file:biz.digitalindustry.nfl.draft.services.Draft.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www .j av a2s . 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 Draft</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet Draft at " + request.getContextPath() + "</h1>"); out.println("</body>"); out.println("</html>"); } finally { out.close(); } }
From source file:com.jiangyifen.ec2.servlet.http.common.filter.HttpCommonFilter.java
/** * @Description ??????/* w ww . ja v a 2 s .c om*/ * * @author JRH * @date 201488 ?12:43:21 * @param response HttpServletResponse * @param commonRespBo ?? * @throws IOException */ private void operateResponse(HttpServletResponse response, CommonRespBo commonRespBo) throws IOException { response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); response.setContentType("text/plain"); out.println("" + GsonUtil.toJson(commonRespBo)); out.close(); }
From source file:edu.cornell.library.scholars.webapp.controller.api.DistributeDataApiController.java
private void do400BadRequest(String message, HttpServletResponse resp) throws IOException { log.debug("400BadRequest: " + message); resp.setStatus(400);/* ww w. j a v a 2 s . co m*/ resp.getWriter().println(message); }
From source file:DedicatedConnectionServlet.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>A Dedicated Connection</title>"); out.println("</head>"); out.println("<body>"); Statement statement = null;/*from w ww.j a v a 2 s .co m*/ ResultSet resultSet = null; String userName = null; try { // test the connection statement = connection.createStatement(); resultSet = statement.executeQuery("select initcap(user) from sys.dual"); if (resultSet.next()) userName = resultSet.getString(1); } catch (SQLException e) { out.println("DedicatedConnection.doGet() SQLException: " + e.getMessage() + "<p>"); } finally { if (resultSet != null) try { resultSet.close(); } catch (SQLException ignore) { } if (statement != null) try { statement.close(); } catch (SQLException ignore) { } } out.println("Hello " + userName + "!<p>"); out.println("This Servlet's database connection was created on " + new java.util.Date(connected) + "<p>"); out.println("</body>"); out.println("</html>"); }