Example usage for javax.servlet.http HttpServletResponse getWriter

List of usage examples for javax.servlet.http HttpServletResponse getWriter

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse getWriter.

Prototype

public PrintWriter getWriter() throws IOException;

Source Link

Document

Returns a PrintWriter object that can send character text to the client.

Usage

From source file:com.jspcr.servlets.K2MServlet.java

/**
* Handles a GET request//from   w w w . j av  a 2  s. c o m
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // Set up for creating HTML output

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    // Generate heading

    out.println("<html>" + "<head>" + "<title>Fuel Efficiency Conversion Chart</title>" + "</head>" + "<body>"
            + "<center>" + "<h1>Fuel Efficiency Conversion Chart</h1>"
            + "<table border='1' cellpadding='3' cellspacing='0'>" + "<tr>" + "<th>Kilometers per Liter</th>"
            + "<th>Miles per Gallon</th>" + "</tr>");

    // Generate table

    for (double kmpl = 5; kmpl <= 20; kmpl += 1.0) {
        double mpg = kmpl * CONVERSION_FACTOR;
        out.println("<tr>" + "<td align='right'>" + FMT.format(kmpl) + "</td>" + "<td align='right'>"
                + FMT.format(mpg) + "</td>" + "</tr>");
    }

    // Generate footer

    out.println("</table>" + "</center>" + "</body>" + "</html>");
}

From source file:org.blanco.gae.blog.BlogServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    try {//from   w w w. j a  v  a2  s  .com
        req.getRequestDispatcher("blog_form.jsp").forward(req, resp);
    } catch (ServletException e) {
        e.printStackTrace(resp.getWriter());
    }
}

From source file:com.antelink.sourcesquare.server.servlet.PublishServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
    response.setContentType("application/json;charset=utf-8");
    Gson gson = new Gson();
    try {//from w  w w .j a v  a  2  s.co  m
        response.getWriter().append(gson.toJson(this.sourceSquareResult != null));
    } catch (IOException e) {
        logger.error("error getting the server state", e);
    }
}

From source file:com.kdab.daytona.Logger.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("Use PUT to deliver content to notify");
    out.flush();//from  www . j  a  v  a  2s.c om
    out.close();
}

From source file:geo.controller.LoadDataServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  ww w  . 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");
    PrintWriter out = response.getWriter();

    try {
        ArrayList<Transaction> transactionList = TransactionDAO.getTransactionList();

        JSONArray jsonArray = new JSONArray();
        int index = 0;

        //hardcode to remove error in geocode
        for (int i = 0; i < transactionList.size(); i++) {
            if (transactionList.get(i).postalCode.equals("158744")) {
                continue;
            }
            jsonArray.add(index++, transactionList.get(i).getJSONObject());
        }

        out.println(jsonArray.toJSONString());

    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:ModuleServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    out.println("<html><head>");
    RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/functions.js");
    dispatcher.include(request, response);

    out.println("<title>Client Forms</title></head><body>");

    out.println("<h2>Enter Your Name and Email</h2>");
    out.println(/*  www. j  a va  2  s .c  o m*/
            "<form action=\"/home/displayHeaders.jsp\" name=\"entryForm\" onSubmit=\" return CheckEmail(this.email.value)\">");
    out.println("<table border=\"0\"><tr><td valign=\"top\">");
    out.println(
            "First and last name: </td>  <td valign=\"top\"><input type=\"text\" name=\"name\" size=\"20\"></td></tr>");
    out.println("<tr><td valign=\"top\">");
    out.println("Email: </td>  <td valign=\"top\"><input type=\"text\" name=\"email\" size=\"20\"></td>");
    out.println("<tr><td valign=\"top\"><input type=\"submit\" value=\"Submit\" ></td>");
    out.println("</tr></table></form>");

    out.println("</body></html>");

}

From source file:com.redoute.datamap.servlet.datamap.DeleteDatamap.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w w  w . ja va  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");
    PrintWriter out = response.getWriter();
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);

    try {
        String name = policy.sanitize(request.getParameter("id"));

        ApplicationContext appContext = WebApplicationContextUtils
                .getWebApplicationContext(this.getServletContext());
        IDatamapService datamapService = appContext.getBean(IDatamapService.class);
        IFactoryDatamap factoryDatamap = appContext.getBean(IFactoryDatamap.class);

        Datamap sqlLib = factoryDatamap.create(Integer.valueOf(name), null, null, null, null, null, null, null,
                null, null);
        datamapService.deleteDatamap(sqlLib);

    } finally {
        out.close();
    }
}

From source file:fish.payara.examples.jdays2016.springboot.DataLoaderServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w w  w.  j a v a2 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");
    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 DataLoader</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet DataLoader at " + request.getContextPath() + "</h1>");

        out.println("Loaded " + loader.parseFile(new File(request.getParameter("file"))) + "records");

        out.println("</body>");
        out.println("</html>");
    }
}

From source file:com.egreen.tesla.server.api.config.resolver.RequestResolver.java

private void sendErrorMessage(HttpServletResponse resp, String message) throws IOException {
    resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    resp.getWriter().print("<html><head><title>Oops an error happened!</title></head>");
    resp.getWriter().print("<body>" + message + "!</body>");
    resp.getWriter().println("</html>");
}

From source file:com.ibm.ws.lars.rest.ErrorHandler.java

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setStatus(500);//  w  w w.  ja  v a  2s.c  o  m
    response.setContentType(MediaType.APPLICATION_JSON);
    PrintWriter printWriter = response.getWriter();
    JsonGenerator frontPageJsonGenerator = new JsonFactory().createGenerator(printWriter);
    frontPageJsonGenerator.setPrettyPrinter(new DefaultPrettyPrinter());

    frontPageJsonGenerator.writeStartObject();
    frontPageJsonGenerator.writeStringField("message",
            "Internal server error, please contact the server administrator");
    frontPageJsonGenerator.writeNumberField("statusCode", response.getStatus());
    frontPageJsonGenerator.writeEndObject();

    frontPageJsonGenerator.flush();
    frontPageJsonGenerator.close();
}