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:com.jmu.util.ResponseJsonUtils.java

public static void writeJSON(ServletResponse response, String json) {
    try {/*from   w  w w.ja  v a2s.  c o  m*/
        response.setContentType("application/json; charset=UTF-8");
        writeJSON(response.getWriter(), json);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.jmu.util.ResponseJsonUtils.java

public static void writeJSON(ServletResponse response, AjaxResponse json) {
    try {//  w  ww. j ava2 s . c om
        response.setContentType("application/json; charset=UTF-8");
        writeJSON(response.getWriter(), json);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.tek271.reverseProxy.servlet.ContentUtils.java

public static void copyText(String text, ServletResponse response, ContentType contentType) {
    //response.setCharacterEncoding(contentType.charset);
    response.setContentType(contentType.value);
    try {//  w  ww .j a  v a  2s .c om
        response.getWriter().print(text);
    } catch (IOException e) {
        Throwables.propagate(e);
    }
}

From source file:org.apache.hadoop.util.ServletUtil.java

/**
 * Initial HTML header//from   w w  w.  j a va 2s .c  om
 */
public static PrintWriter initHTML(ServletResponse response, String title) throws IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>\n" + "<link rel='stylesheet' type='text/css' href='/static/hadoop.css'>\n" + "<title>"
            + title + "</title>\n" + "<body>\n" + "<h1>" + title + "</h1>\n");
    return out;
}

From source file:com.netspective.sparx.util.HttpUtils.java

public static void includeServletResourceContent(Writer writer, HttpServletValueContext vc, String includePath,
        String valueContextAttrName) throws IOException, ServletException {
    ServletRequest request = vc.getRequest();
    ServletResponse response = vc.getResponse();

    RequestDispatcher rd = request.getRequestDispatcher(includePath);

    if (writer != response.getWriter())
        response = new AlternateOutputDestServletResponse(writer, response);

    request.setAttribute(valueContextAttrName, vc);
    rd.include(request, response);/*from  w w w. j  a  va  2 s. c o m*/
    request.removeAttribute(valueContextAttrName);
}

From source file:org.codehaus.groovy.grails.web.pages.GSPResponseWriter.java

/**
 * Static factory methdirectWritingod to create the writer.
 * @param response//from ww w  . j  av a  2s .co m
 * @param max
 * @return  A GSPResponseWriter instance
 */
private static GSPResponseWriter getInstance(final ServletResponse response, final int max) {
    final BoundedCharsAsEncodedBytesCounter bytesCounter = new BoundedCharsAsEncodedBytesCounter();

    final StreamCharBuffer streamBuffer = new StreamCharBuffer(max, 0, max);
    streamBuffer.setChunkMinSize(max / 2);
    streamBuffer.setNotifyParentBuffersEnabled(false);

    final StreamCharBuffer.LazyInitializingWriter lazyResponseWriter = new StreamCharBuffer.LazyInitializingWriter() {
        public Writer getWriter() throws IOException {
            return response.getWriter();
        }
    };

    if (!(response instanceof GrailsContentBufferingResponse)) {
        streamBuffer.connectTo(new StreamCharBuffer.LazyInitializingMultipleWriter() {
            public Writer getWriter() throws IOException {
                return null;
            }

            public LazyInitializingWriter[] initializeMultiple(StreamCharBuffer buffer, boolean autoFlush)
                    throws IOException {
                final StreamCharBuffer.LazyInitializingWriter[] lazyWriters;
                if (CONTENT_LENGTH_COUNTING_ENABLED) {
                    lazyWriters = new StreamCharBuffer.LazyInitializingWriter[] {
                            new StreamCharBuffer.LazyInitializingWriter() {
                                public Writer getWriter() throws IOException {
                                    bytesCounter.setCapacity(max * 2);
                                    bytesCounter.setEncoding(response.getCharacterEncoding());
                                    return bytesCounter.getCountingWriter();
                                }
                            }, lazyResponseWriter };
                } else {
                    lazyWriters = new StreamCharBuffer.LazyInitializingWriter[] { lazyResponseWriter };
                }
                return lazyWriters;
            }
        }, AUTOFLUSH_ENABLED);
    } else {
        streamBuffer.connectTo(lazyResponseWriter);
    }

    if (instantiator != null) {
        GSPResponseWriter instance = (GSPResponseWriter) instantiator.newInstance();
        instance.initialize(streamBuffer, response, bytesCounter);
        return instance;
    } else {
        return new GSPResponseWriter(streamBuffer, response, bytesCounter);
    }
}

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

@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    PrintWriter out = res.getWriter();
    String json = FileUtils.readFileToString(new File(TestServlet.getBaseDir(this) + "/metrics.json"));
    out.println(json);//from  w w w .j  av a2s  . com
}

From source file:org.sonar.wsclient.MetricServlet.java

@Override
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();

    String json = IOUtils.toString(MetricServlet.class.getResourceAsStream("/metrics/many_metrics.json"));
    out.println(json);//from   ww  w  . j a v a  2  s  .  c o  m
}

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

@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    PrintWriter out = res.getWriter();
    String profile = req.getParameter("profile");
    profile = profile.replace(' ', '_');
    String json = FileUtils//from  w  w w .ja va2 s  . c om
            .readFileToString(new File(TestServlet.getBaseDir(this) + "/rules/" + profile + ".json"));
    out.println(json);
}

From source file:br.com.bancooriginal.notificacao.servlet.SampleServletApplication.java

@SuppressWarnings("serial")
@Bean//from  w w  w. j  av a2s  .  co  m
public Servlet dispatcherServlet() {
    return new GenericServlet() {
        @Override
        public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
            res.setContentType("text/plain");
            res.getWriter().append("Hello World");
        }
    };
}