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:org.cloudfoundry.tools.timeout.TimeoutResourceHttpRequestHandler.java

@Override
protected void writeContent(HttpServletResponse response, Resource resource) throws IOException {
    String content = getContent(resource);
    FileCopyUtils.copy(content, response.getWriter());
}

From source file:com.gson.web.WeChatPayNotifyServlet.java

/**
 * //from w  w  w . j a  v a2  s  .c o m
 * @param response
 * @param msg
 */
private void writeString(HttpServletResponse response, String msg) {
    try {
        response.getWriter().write(msg);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:azkaban.web.JobManagerServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.getWriter().write("Hello!");
}

From source file:com.mykarsol.appconnectivity.imageload.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */

        String bytestring = request.getParameter("bytestring");
        System.out.println(bytestring);
        String p = getServletContext().getRealPath("\\images");
        File f = new File(p);
        if (!f.exists()) {
            f.mkdir();/*from   ww w  . j av  a  2s.c  o m*/
        }
        System.out.println("---------" + p);
        FileOutputStream fos = new FileOutputStream(p + "\\img" + i + ".jpeg"); //change path of image according to you
        String imgpath = "\\img" + i + ".jpeg";
        byte[] byteArray = Base64.decodeBase64(bytestring);
        fos.write(byteArray);
        out.println(imgpath);
        i++;
    }
}

From source file:com.graphhopper.http.GHBaseServlet.java

public void writeResponse(HttpServletResponse res, String str) {
    try {/*from   w ww  . jav  a2  s . co  m*/
        res.setStatus(SC_OK);
        res.getWriter().append(str);
    } catch (IOException ex) {
        logger.error("Cannot write message:" + str, ex);
    }
}

From source file:AreaCode.java

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

    String msg = null;//from   ww w.  ja  v  a 2  s . c o m

    String code = req.getParameter("code");
    String region = null;
    if (code != null) {
        region = lookup.getProperty(code);
    }

    out.println("<?xml version=\"1.0\"?>");
    out.println("<!DOCTYPE wml PUBLIC " + "\"-//WAPFORUM//DTD WML 1.1//EN\" "
            + "\"http://www.wapforum.org/DTD/wml_1.1.xml\">");

    out.println("<wml>");
    out.println("<card id=\"Code\" title=\"Code\">");
    out.println("  <p>");
    out.println("  Area code '" + code + "'<br/>");
    if (region != null) {
        out.println("  is " + region + ".<br/>");
    } else {
        out.println("  is not valid.<br/>");
    }
    out.println("  </p>");
    out.println("</card>");
    out.println("</wml>");
}

From source file:SessionSnoop.java

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

    HttpSession session = req.getSession();

    Integer count = (Integer) session.getAttribute("count");
    if (count == null)
        count = new Integer(1);
    else//  w  ww  .  j a va 2s .  c o  m
        count = new Integer(count.intValue() + 1);
    session.setAttribute("count", count);

    out.println("<HTML><HEAD><TITLE>Session Count</TITLE></HEAD>");
    out.println("<BODY><H1>Session Count</H1>");

    out.println("You've visited this page " + count + ((count == 1) ? " time." : " times."));

    out.println("<P>");

    out.println("<H3>Here is your saved session data:</H3>");
    Enumeration e = session.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        out.println(name + ": " + session.getAttribute(name) + "<BR>");
    }

    out.println("<H3>Here are some vital stats on your session:</H3>");
    out.println("Session id: " + session.getId() + " <I>(keep it secret)</I><BR>");
    out.println("New session: " + session.isNew() + "<BR>");
    out.println("Timeout: " + session.getMaxInactiveInterval());
    out.println("<I>(" + session.getMaxInactiveInterval() / 60 + " minutes)</I><BR>");
    out.println("Creation time: " + session.getCreationTime());
    out.println("<I>(" + new Date(session.getCreationTime()) + ")</I><BR>");
    out.println("Last access time: " + session.getLastAccessedTime());
    out.println("<I>(" + new Date(session.getLastAccessedTime()) + ")</I><BR>");

    out.println("Requested session ID from cookie: " + req.isRequestedSessionIdFromCookie() + "<BR>");
    out.println("Requested session ID from URL: " + req.isRequestedSessionIdFromURL() + "<BR>");
    out.println("Requested session ID valid: " + req.isRequestedSessionIdValid() + "<BR>");

    out.println("<H3>Test URL Rewriting</H3>");
    out.println("Click <A HREF=\"" + res.encodeURL(req.getRequestURI()) + "\">here</A>");
    out.println("to test that session tracking works via URL");
    out.println("rewriting even when cookies aren't supported.");

    out.println("</BODY></HTML>");
}

From source file:edu.lafayette.metadb.web.userman.CreateUser.java

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*//*from   w  w  w  .  jav a2 s. c  om*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    JSONObject output = new JSONObject();
    try {
        String username = request.getParameter("username");
        String type = request.getParameter("permission");
        String authType = request.getParameter("auth-type");
        //MetaDbHelper.note("Auth Type: "+authType);
        String pwd = (authType.equals("Local") ? request.getParameter("confirm-password") : getRandomPass());

        if (UserManDAO.createUser(username, pwd, type, authType)) {
            output.put("success", true);
            output.put("message", type + " " + username + " created successfully!!");
            output.put("username", username);
            output.put("local", authType.equals("Local"));
            output.put("admin", type.equals("admin"));

            HttpSession session = request.getSession(false);
            if (session != null && session.getAttribute(Global.SESSION_BYPASS) == null) {
                String userName = (String) session.getAttribute(Global.SESSION_USERNAME);
                SysLogDAO.log(userName, Global.SYSLOG_SYSTEM,
                        "User " + username + " created with permission " + type);
            }
        } else {
            output.put("success", false);
            output.put("message", "User cannot be created");
            HttpSession session = request.getSession(false);
            if (session != null && session.getAttribute(Global.SESSION_BYPASS) == null) {
                String userName = (String) session.getAttribute(Global.SESSION_USERNAME);
                SysLogDAO.log(userName, Global.SYSLOG_ERROR, "Failure to create user " + userName);
            }
        }
        out.print(output);
    } catch (Exception e) {
        MetaDbHelper.logEvent(e);
    }
    out.flush();
}

From source file:org.openmrs.module.sync.web.CreateChildServlet.java

private void reply(HttpServletResponse response, String str, String color) {
    try {/*from   ww  w. java 2s  .co  m*/
        response.getWriter().println("<html><body onload=\"window.parent.showUploadResponse('" + str + "','"
                + color + "');\"></body></html>");
    } catch (Exception ex) {
        log.warn(ex.toString());
        ex.printStackTrace();
    }
}

From source file:de.knurt.fam.template.controller.json.JSONController2.java

/**
 * print out json with the key and values got from
 * {@link JSONController2#getKeyAndValues(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}
 * //from ww  w  .  j a v  a2 s .co  m
 * @param rq
 *            request
 * @param rs
 *            response
 * @return null
 */
public ModelAndView handleRequest(HttpServletRequest rq, HttpServletResponse rs) {
    PrintWriter pw = null;
    try {
        rs.setHeader("Content-type", "application/json");
        pw = rs.getWriter();
        IOUtils.write(this.getJSONObject().toString(), pw);
    } catch (IOException ex) {
        this.onIOException(ex);
    } finally {
        IOUtils.closeQuietly(pw);
    }
    return null;
}