Example usage for javax.servlet ServletResponse getWriter

List of usage examples for javax.servlet ServletResponse getWriter

Introduction

In this page you can find the example usage for javax.servlet ServletResponse 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 service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    out.println("Init Parameters:");
    Enumeration e = getInitParameterNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        out.println(name + ": " + getInitParameter(name));
    }//from  ww  w . j  a v  a 2s  .co m
}

From source file:GetKey.java

public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    String key = getInitParameter("key");
    String host = req.getServerName();
    int port = req.getServerPort();

    if (!keyFitsServer(key, host, port)) {
        out.println("Pirated!");
    } else {/*from www  .j  av  a 2  s.c  om*/
        out.println("Valid");
    }
}

From source file:org.everit.jetty.server.ecm.tests.EchoRemoteInfoServlet.java

@Override
public void service(final ServletRequest req, final ServletResponse res) throws ServletException, IOException {
    PrintWriter writer = res.getWriter();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("remoteAddr", req.getRemoteAddr());
    jsonObject.put("remoteHost", req.getRemoteHost());
    jsonObject.put("remotePort", req.getRemotePort());
    jsonObject.put("serverName", req.getServerName());
    jsonObject.put("serverPort", req.getServerPort());
    jsonObject.put("protocol", req.getProtocol());
    jsonObject.put("secure", req.isSecure());

    writer.write(jsonObject.toString());

}

From source file:ServerSnoop.java

public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    ServletContext context = getServletContext();
    out.println("req.getServerName(): " + req.getServerName());
    out.println("req.getServerPort(): " + req.getServerPort());
    out.println("context.getServerInfo(): " + context.getServerInfo());
    out.println("getServerInfo() name: " + getServerInfoName(context.getServerInfo()));
    out.println("getServerInfo() version: " + getServerInfoVersion(context.getServerInfo()));
    out.println("context.getAttributeNames():");
    Enumeration e = context.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        out.println("  context.getAttribute(\"" + name + "\"): " + context.getAttribute(name));
    }//from w ww . j  a v  a2  s  .c o m
}

From source file:org.nuxeo.license.filter.LicenseGuardFilter.java

protected void handleNoValidLicense(ServletRequest request, ServletResponse response) throws IOException {
    String message = "No valid license found!";
    log.warn(message);/* w  w w  .java2s. c  o m*/
    response.getWriter().write(message);
    // XXX redirect or whatever
}

From source file:org.sonar.ide.test.TestServlet.java

@Override
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    String json;/*from  w ww  . j  a v a2 s .  c o  m*/
    try {
        String resourceKey = request.getParameter("resource");
        String[] parts = resourceKey.split(":");
        switch (parts.length) {
        case 2:
            json = loadProjectData(parts[0], parts[1]);
            break;
        case 3:
            json = loadFileData(parts[0], parts[1], parts[2]);
            break;
        default:
            json = "[]";
            break;
        }
    } catch (Exception e) {
        SonarTestServer.LOG.error(e.getMessage(), e);
        json = "[]";
    }
    out.println(json);
}

From source file:MyServlet.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    chain.doFilter(request, response);// w  ww  .j  av  a2 s .c  o  m
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("The filter got this message: " + filterConfig.getInitParameter("message"));
}

From source file:org.ng200.openolympus.controller.auth.RecaptchaAuthenticationFilter.java

private void recaptchaError(ServletRequest request, ServletResponse response, List<String> recaptchaErrors)
        throws IOException {

    response.setContentType("application/json");
    AuthenticationResponder.writeLoginStatusJson(response.getWriter(), "unknown", recaptchaErrors);
}

From source file:org.apache.myfaces.custom.ajaxchildcombobox.HtmlAjaxChildComboBoxRenderer.java

public void encodeAjax(FacesContext context, UIComponent uiComponent) throws IOException {

    String parentValue = (String) context.getExternalContext().getRequestParameterMap().get("parentValue");

    ServletResponse response = (ServletResponse) context.getExternalContext().getResponse();
    PrintWriter writer = response.getWriter();

    StringBuffer xml = new StringBuffer();

    MethodExpression mb = ((AjaxChildComboBox) uiComponent).getAjaxSelectItemsMethod();
    SelectItem[] options = (SelectItem[]) mb.invoke(context.getELContext(), new Object[] { parentValue });

    xml.append("<?xml version=\"1.0\"?>\n");
    xml.append("<response>\n");
    for (int i = 0; i < options.length; i++) {
        xml.append(BEGIN_OPTION);//from   w w w  .j a va 2 s .  co  m
        xml.append(BEGIN_OPTION_TEXT).append(options[i].getLabel()).append(END_OPTION_TEXT);
        xml.append(BEGIN_OPTION_VALUE).append(options[i].getValue()).append(END_OPTION_VALUE);
        xml.append(END_OPTION);
    }
    xml.append("</response>");

    writer.write(xml.toString());

}

From source file:com.anite.ocelot.CachedServletResponse.java

/**
 * @param arg0//from  www  .  j av  a  2 s  . com
 */
public CachedServletResponse(javax.servlet.ServletResponse arg0) {
    super(arg0);
    if (log.isInfoEnabled()) {
        log.info("CachedServletResponse");
    }
    try {
        pw = new CachedPrintWriter(arg0.getWriter());
    } catch (IOException e) {
        log.error("Exception caught :" + e.getMessage(), e);
    }

}