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:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setBufferSize(8 * 1024); // 8K buffer
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    int size = res.getBufferSize(); // returns 8096 or greater

    // Record the default size, in the log
    log("The default buffer size is " + size);

    out.println("The client won't see this");
    res.reset();//from w ww. j  av a2  s .  c o  m
    out.println("And this won't be seen if sendError() is called");
    if (req.getParameter("important_parameter") == null) {
        res.sendError(res.SC_BAD_REQUEST, "important_parameter needed");
    }
}

From source file:WebAppProperties.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();
    ServletContext context = getServletContext();
    String displayName = context.getServletContextName();
    if (displayName == null) {
        displayName = "(no display-name element defined)";
    }/*from w w  w .ja  v a 2 s .c om*/

    out.println("<html>");
    out.println("<head>");
    out.println("<title>Web Application Properties");
    out.println("</title>");
    out.println("</head><body>");
    out.println("<h1>Web Application Properties</h2>");
    out.println("<br>Name: " + displayName);
    out.println("<br>Context: " + req.getContextPath());

    out.println("<h2><center>");
    out.println("Initialization Parameters</center></h2>");
    out.println("<br>");

    out.println("<center><table border width=80%>");

    Enumeration e = context.getInitParameterNames();

    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        out.println("<tr>");
        out.println("<td>" + name + "</td>");
        out.println("<td>" + context.getInitParameter(name) + "</td>");
        out.println("</tr>");
    }
    out.println("</table></center>");

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

From source file:com.st.qunar.order.web.order.OrderController.java

@RequestMapping(value = "allExport")
public void allExport(@RequestParam String key, HttpServletResponse resp) throws IOException {
    resp.setCharacterEncoding("UTF-8");
    PrintWriter pw = resp.getWriter();
    if (key.equalsIgnoreCase("kxhu")) {
        orderExportService.allExport();//from   ww  w  .j  a va 2s .co  m
        pw.write("allexport");
    } else {
        pw.write("error key all export");
    }
    pw.close();
}

From source file:org.ktunaxa.referral.server.mvc.UploadView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    response.setContentType("text/html");
    response.getWriter().println("<html>");
    response.getWriter().println("<body>");
    response.getWriter().println("<script type=\"text/javascript\">");
    UploadResponse ur = (UploadResponse) model.get(RESPONSE);
    SerializerState state = new SerializerState();
    if (ur != null) {
        JSONObject result = (JSONObject) getSerializer().marshall(state, ur.getResultMap());
        if (ur.isSuccess()) {
            response.getWriter()//from   ww w .j  a  va  2s. c om
                    .println(MessageFormat.format(getSuccessScript(), result.getJSONObject("map").toString()));
        } else {
            response.getWriter()
                    .println(MessageFormat.format(getErrorScript(), result.getJSONObject("map").toString()));
        }
    } else {
        response.getWriter()
                .println(MessageFormat.format(getErrorScript(), getSerializer().toJSON("server error")));
    }
    response.getWriter().println("</script>");
}

From source file:com.imagelake.android.changephoneno.Servlet_ChangePhoneno.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    try {/*from w  w w  .j a v  a 2  s.  c  om*/
        String type = request.getParameter("type");
        if (type != null) {
            String uid = request.getParameter("uid");

            if (type.equals("load_phone")) {
                if (uid != null) {
                    User u = udi.getUser(Integer.parseInt(uid));
                    if (u != null) {
                        JSONObject jo = new JSONObject();
                        jo.put("phn", u.getPhone());

                        System.out.println(jo.toJSONString());
                        out.write("json=" + jo.toJSONString());
                    } else {
                        out.write("msg=Internal server error,Please try again later.");
                    }
                } else {
                    out.write("msg=Internal server error,Please try again later.");
                }
            } else if (type.equals("update_phone")) {
                String phn = request.getParameter("phn");
                if (phn != null) {
                    boolean k = udi.updatePhoneNo(Integer.parseInt(uid), phn);
                    if (k) {
                        out.write("msg=Successfully Completed.");
                    } else {
                        out.write("msg=Unable to complete the action,Please try again later.");
                    }
                } else {
                    out.write("msg=Internal server error,Please try again later.");
                }
            }
        } else {
            out.write("msg=Internal server error,Please try again later.");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.imagelake.earnings.Servlet_EarningsValues.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    try {//from   www.  java2 s.c o m
        String uid = request.getParameter("uid");
        if (uid != null && !uid.equals("")) {

            uidd = Integer.parseInt(uid);

            PaymentPreferences pp = ppimp.getPendingEarning(uidd, 1);
            double pd = 00.00;
            double ad = 00.00;
            if (pp != null) {
                pd = pp.getAmount();
                DecimalFormat df1 = new DecimalFormat("#.##");
                pd = Double.valueOf(df1.format(pd));

            }

            SellerIncome sin = sidi.getSellerIncome(uidd);
            ad = sin.getTotal();
            DecimalFormat df = new DecimalFormat("#.##");
            ad = Double.valueOf(df.format(ad));

            double netamo = ad - pd;
            DecimalFormat df2 = new DecimalFormat("#.##");
            netamo = Double.valueOf(df2.format(netamo));

            JSONObject jo = new JSONObject();
            jo.put("pe", pd);
            jo.put("ab", ad);
            jo.put("ne", netamo);

            out.write("json=" + jo.toJSONString());
        }
    } catch (Exception e) {
        e.printStackTrace();

    }
}

From source file:PostServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!"text/xml".equals(request.getContentType())) {
        response.getWriter().println("Please post as text/xml.");
    } else {//from w  w w . java2s  .  co m
        try {
            Document doc = builder.build(request.getReader());
            StringBuffer buff = new StringBuffer();
            buff.append("You searched for name '" + nameXPath.valueOf(doc) + "'");
            String year = yearXPath.valueOf(doc);
            if (!"notselected".equals(year)) {
                buff.append(" and year '" + year + "'");
            }
            buff.append(".");
            response.getWriter().print(buff.toString());
        } catch (JDOMException e) {
            response.getWriter().print("Error getting search terms: " + e.getMessage());
        }
    }
}

From source file:com.Accenture.Java.NewServlet.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/* w  w w  . j  ava 2  s  .co  m*/
 * @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 {
    try (PrintWriter out = response.getWriter()) {
        String p1 = request.getParameter("p1");
        String p2 = request.getParameter("p2");
        if (p1 != p2) {
            out.println("<label id='lblshow'>Password dont Match</label>");
        } else {
            out.println("<label id='lblshow'>Password Matched</label>");
        }
    }
}

From source file:org.dhara.portal.web.northToAiravataConnector.WorkflowExecutionServlet.java

@RequestMapping(value = { "/connect/ExecutionServlet",
        "/connect/ExecutionServlet/" }, method = RequestMethod.GET)
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws javax.servlet.ServletException, IOException {
    PrintWriter pw = response.getWriter();
    String workflowId = request.getParameter("workflowId");
    try {/*from w w  w. j  av a2  s .  c  om*/
        ApplicationContext context = WebApplicationContextUtils
                .getRequiredWebApplicationContext(getServletContext());
        AiravataClientAPIService airavataClientAPIService = (AiravataClientAPIService) context
                .getBean("airavataAPIService");
        Map<String, Object> inputs = new HashMap<String, Object>();
        Workflow workflow = airavataClientAPIService.getWorkflow(workflowId);
        for (WorkflowInput workflowInput : workflow.getWorkflowInputs()) {
            inputs.put(workflowInput.getName(), request.getParameter(workflowInput.getName()));
        }
        outputs = airavataClientAPIService.executeWorkflow(inputs, workflowId); //     _52NorthExecuteWorkFlowTest
        JSONObject jsonObject = new JSONObject(outputs);
        PrintWriter printWriter = response.getWriter();
        printWriter.write(jsonObject.toJSONString());
    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:IncludeServlet.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>");
    out.println("<head>");
    out.println("<title>Include Servlet</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Welcome To Our Universe</h1>");
    out.println("Imagine the rest of the page here.<br><br>");
    //Include the copyright information
    RequestDispatcher dispatcher = request.getRequestDispatcher("/CopyRight");
    dispatcher.include(request, response);

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

    out.close();//w  w  w. j a  v a2s.  c  o m

}