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

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();
    HttpSession session = req.getSession(true);
    SessionObject o = new SessionObject(getServletContext());
    session.setAttribute("Binder.object", o);
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Session Binder</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("Object bound to session " + session.getId());

    out.println("</body>");
    out.println("</html>");
    out.flush();/*  www . j  a va2  s. c o m*/
}

From source file:Main.java

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

    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    // Print out the IP address of the caller
    out.println(request.getRemoteAddr());

}

From source file:com.liusoft.util.hsqldb.HSQLEngineServlet.java

/**
 * HSQLEngine??/*  w w w  .j a va 2s. c om*/
 */
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    PrintWriter out = res.getWriter();
    if (engine == null)
        out.println("HSQLDB Engine initialize failed.");
    else if (engine.isRunning())
        out.println("HSQLDB Engine is running...");
    else
        out.println("HSQLDB Engine is stopped.");
}

From source file:com.msopentech.odatajclient.testauthproxy.staticmetadata.StaticMetadataServlet.java

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {

    resp.setContentType("application/xml;charset=UTF-8");
    resp.getWriter().write(IOUtils.toString(getClass().getResourceAsStream("/static-metadata.xml"), "UTF-8"));
}

From source file:MyServlet.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>");
    out.println("Using the init Method");
    out.println("</TITLE>");
    out.println("</HEAD>");
    out.println("<BODY>");
    out.println("<H1>Using the init Method</H1>");
    out.println(msg);//from w w w.  j a  v  a  2s .co m
    out.println("</BODY>");
    out.println("</HTML>");
}

From source file:com.job.portal.servlets.CompanyServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    JSONObject obj = new JSONObject();
    JSONArray arr = null;/*from   w w w .jav  a 2s  .  c  o m*/
    String param = null;
    Map<String, String[]> m = request.getParameterMap();
    CompanyManager cm = new CompanyManager();
    HttpSession sess = request.getSession(false);
    UserDetails ud = (UserDetails) sess.getAttribute("user");
    CompanyMaster cMaster = null;
    try {
        obj.put("status", false);
        if (request.getParameter("param") != null) {
            param = request.getParameter("param");
            if (param.equalsIgnoreCase("addCompany")) {
                cMaster = cm.addCompany(m, ud);
                if (cMaster != null && cMaster.getCompanyId() > 0) {
                    obj.put("status", true);
                    obj.put("msg", "Company added");
                } else {
                    obj.put("msg", "There seems to be some problem try again later");
                }
            }
        }
    } catch (Exception e) {
        LogOut.log.error("In " + new Object() {
        }.getClass().getEnclosingClass().getName() + "." + new Object() {
        }.getClass().getEnclosingMethod().getName() + " " + e);
    } finally {
        out.close();
    }
}

From source file:Main.java

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

    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    Enumeration en = request.getParameterNames();

    while (en.hasMoreElements()) {
        String paramName = (String) en.nextElement();
        out.println(paramName + " = " + request.getParameter(paramName) + "<br/>");
    }/*from   w  w  w  .  j  av  a  2s . c  o m*/
}

From source file:ErrorDisplay.java

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

    String code = null, message = null, type = null;
    Object codeObj, messageObj, typeObj;

    // Retrieve the three possible error attributes, some may be null
    codeObj = req.getAttribute("javax.servlet.error.status_code");
    messageObj = req.getAttribute("javax.servlet.error.message");
    typeObj = req.getAttribute("javax.servlet.error.exception_type");

    // Convert the attributes to string values
    if (codeObj != null)
        code = codeObj.toString();//ww  w  . ja v a  2s.c  o m
    if (messageObj != null)
        message = messageObj.toString();
    if (typeObj != null)
        type = typeObj.toString();

    // The error reason is either the status code or exception type
    String reason = (code != null ? code : type);

    out.println("<HTML>");
    out.println("<HEAD><TITLE>" + reason + ": " + message + "</TITLE></HEAD>");
    out.println("<BODY>");
    out.println("<H1>" + reason + "</H1>");
    out.println("<H2>" + message + "</H2>");
    out.println("<HR>");
    out.println("<I>Error accessing " + req.getRequestURI() + "</I>");
    out.println("</BODY></HTML>");
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain; charset=Shift_JIS");
    PrintWriter out = res.getWriter();
    res.setHeader("Content-Language", "ja");

    Locale locale = new Locale("ja", "");
    DateFormat full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
    out.println("In Japanese:");

    try {//from   ww w  . jav  a  2  s  .c o m
        FileInputStream fis = new FileInputStream(req.getRealPath("/HelloWorld.ISO-2022-JP"));
        InputStreamReader isr = new InputStreamReader(fis, "ISO-2022-JP");
        BufferedReader reader = new BufferedReader(isr);
        String line = null;
        while ((line = reader.readLine()) != null) {
            out.println(line);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    out.println(full.format(new Date()));
}

From source file:MyServlet.java

public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    String account = req.getParameter("account");
    String password = req.getParameter("password");
    String pin = req.getParameter("pin");

    if (!allowUser(account, password, pin)) {
        out.println("<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD>");
        out.println("<BODY>Your login and password are invalid.<BR>");
        out.println("You may want to <A HREF=\"/login.html\">try again</A>");
        out.println("</BODY></HTML>");
    } else {/*from   w w w .  j  a v a  2 s.  c  o  m*/
        out.println("<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD>");
        out.println("<BODY>Your login and password are valid.<BR>");
        out.println("</BODY></HTML>");
        HttpSession session = req.getSession();
        session.setAttribute("logon.isDone", account); // just a marker object

        try {
            String target = (String) session.getAttribute("login.target");
            if (target != null) {
                res.sendRedirect(target);
                return;
            }
        } catch (Exception ignored) {
        }

        //res.sendRedirect("/");
    }
}