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:es.itecban.deployment.executionmanager.web.view.ReportActivityView.java

public void render(Map model, HttpServletRequest req, HttpServletResponse resp) throws Exception {
    PrintWriter out = resp.getWriter();

    resp.setContentType("application/octet-stream");

    ActivityExecReportType report = (ActivityExecReportType) model.get("report");
    out.print(report.getTechnicalActivityExecReport());
    out.flush();//from   w ww  .ja v a  2  s .  c  o m
    out.close();

}

From source file:com.vmware.identity.SharedUtils.java

/**
 * Build mock HttpServletResponse object with a StringWriter
 *  which receives actual response//w  ww  .java 2s .c  om
 * @param sw
 * @param contentType
 * @param expectCookie
 * @return
 * @throws IOException
 */
public static HttpServletResponse buildMockResponseSuccessObject(StringWriter sw, String contentType,
        boolean expectCookie, String contentDispositionValue) throws IOException {
    HttpServletResponse response = createMock(HttpServletResponse.class);
    if (expectCookie) {
        response.addCookie(isA(Cookie.class));
    }
    response.setContentType(contentType);
    if (contentDispositionValue != null && !contentDispositionValue.isEmpty()) {
        response.setHeader("Content-Disposition", contentDispositionValue);
    }
    expect(response.getWriter()).andReturn(new PrintWriter(sw)).anyTimes();
    replay(response);
    return response;
}

From source file:es.itecban.deployment.executionmanager.web.view.ReportView.java

public void render(Map model, HttpServletRequest req, HttpServletResponse resp) throws Exception {
    PrintWriter out = resp.getWriter();

    resp.setContentType("application/octet-stream");

    ExecutionReportType report = (ExecutionReportType) model.get("report");
    //      report.getTechnicalExecutionReport();
    out.print(report.getTechnicalExecutionReport());
    out.flush();/*  www  .j a  v  a 2  s. c  o  m*/
    out.close();

}

From source file:com.github.tuxychandru.spring.mustache.MustacheView.java

@Override
protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    factory.compile(getUrl()).execute(response.getWriter(), model);
}

From source file:com.github.dbourdette.otto.web.controller.IndexController.java

@RequestMapping("/state")
public void state(HttpServletResponse response) throws IOException {
    Writer writer = response.getWriter();

    for (Source source : Source.findAll()) {
        writer.write(source.toString());
    }/*from w w w.  j av a2s. c  o  m*/
}

From source file:com.dien.upload.server.UploadServlet.java

protected static void renderJSONResponse(HttpServletRequest request, HttpServletResponse response,
        String message) throws IOException {

    //json????/*  www  .java2 s .  c  om*/

    response.setContentType("text/html;charset=utf-8");
    PrintWriter out;
    try {
        out = response.getWriter();
        out.write(message);
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:org.apache.dubbo.remoting.http.jetty.JettyHttpBinderTest.java

@Test
public void shouldAbleHandleRequestForJettyBinder() throws Exception {
    int port = NetUtils.getAvailablePort();
    URL url = new URL("http", "localhost", port,
            new String[] { Constants.BIND_PORT_KEY, String.valueOf(port) });
    HttpServer httpServer = new JettyHttpServer(url, new HttpHandler() {
        @Override/*w w  w.  java 2 s  .c  o  m*/
        public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
            response.getWriter().write("Jetty");
        }
    });

    String response = Request.Get(url.toJavaURL().toURI()).execute().returnContent().asString();

    assertThat(response, is("Jetty"));

    httpServer.close();
}

From source file:org.apache.dubbo.remoting.http.tomcat.TomcatHttpBinderTest.java

@Test
public void shouldAbleHandleRequestForTomcatBinder() throws Exception {
    int port = NetUtils.getAvailablePort();
    URL url = new URL("http", "localhost", port,
            new String[] { Constants.BIND_PORT_KEY, String.valueOf(port) });

    HttpServer httpServer = new TomcatHttpBinder().bind(url, new HttpHandler() {
        @Override//from  ww  w .j  av  a  2 s . c  o  m
        public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
            response.getWriter().write("Tomcat");
        }
    });

    String response = Request.Get(url.toJavaURL().toURI()).execute().returnContent().asString();

    assertThat(response, is("Tomcat"));

    httpServer.close();
}

From source file:cc.vidr.servlet.DatumImportServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.getWriter().println("<form action=\"\" method=\"post\" " + "enctype=\"multipart/form-data\">");
    for (int i = 0; i < 10; i++)
        resp.getWriter().println("<input type=\"file\" name=\"file" + i + "\" /><br />");
    resp.getWriter().println("<input type=\"submit\" /></form>");
}

From source file:com.mum.edu.cs472.dictServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    PrintWriter pt = resp.getWriter();
    String word = req.getParameter("word");
    String json = DbConnection.resultSetToJson(word);
    pt.write(json);/*from   w  w  w.  java2 s . c  o m*/
}