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.baswell.routes.JacksonBridge.java

static void sendJackson(Object response, HttpServletResponse servletResponse) throws IOException {
    new ObjectMapper().writeValue(servletResponse.getWriter(), response);
}

From source file:com.jjtree.utilities.JResponse.java

public static void sendJson(HttpServletResponse response, JSONObject json) throws IOException {
    PrintWriter writer = response.getWriter();
    writer.print(json);/*w w w. jav a 2  s.  c o  m*/
    writer.flush();
}

From source file:net.bluehornreader.web.WebUtils.java

public static void showResult(String result, String nextPath, Request request,
        HttpServletResponse httpServletResponse) throws Exception {
    PrintWriter out = httpServletResponse.getWriter();

    out.println("<html>");
    out.println("<head>");
    out.println("<title>Bluehorn Reader</title>");
    out.println("</head>");

    out.println("<body>"); //ttt1 add formatting
    out.println("<h2>" + result + "</h2>");
    out.println("<p/>");
    out.println("<a href=\"" + nextPath + "\">Continue</a>");
    out.println("<p/>");
    out.println("</body>");
    out.println("</html>");

    request.setHandled(true);/* w w  w  .j  a va 2 s.c o m*/
}

From source file:com.bluepandora.therap.donatelife.jsonsender.SendJsonData.java

public static void sendJsonData(HttpServletRequest request, HttpServletResponse response, JSONObject object) {
    response.setContentType("application/json");
    System.out.println(object);/* ww w .  j a v a  2 s .c o  m*/
    try {
        PrintWriter out = response.getWriter();
        out.print(object);
        out.flush();
    } catch (IOException io) {
        io.printStackTrace();
    } catch (Exception error) {
        error.printStackTrace();
    }
}

From source file:eu.delving.services.controller.ServiceController.java

private static void report(HttpServletResponse response, String message) throws IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html><head><title>Resolver</title></head><body><h2>");
    out.println(message);//from  w w w. j  ava 2 s.  c o m
    out.println("</body></html></h2>");
}

From source file:com.intbit.util.ServletUtil.java

public static void printSuccessData(HttpServletResponse response, Map<String, Object> data) throws IOException {
    response.setStatus(HttpServletResponse.SC_OK);
    response.getWriter().write(AppConstants.GSON.toJson(data));
    response.getWriter().flush();/*ww  w.  j  a va2 s. c  o  m*/
}

From source file:com.roncoo.pay.utils.JsonUtils.java

/**
 * Map?,??Json,/*from  w w w. j a  v  a  2 s.  co m*/
 * @param response
 * @param object
 * @throws IOException
 */
public static void responseJson(HttpServletResponse response, Object object) throws IOException {

    Object toJSON = JSONObject.toJSON(object);
    try {
        response.getWriter().write(toJSON.toString());
    } catch (IOException e) {
        LOG.error(e);
    }
}

From source file:cc.kune.core.server.manager.file.FileDownloadManagerUtils.java

/**
 * Return not found404./*w  ww .j a  v  a  2  s. co m*/
 * 
 * @param resp
 *          the resp
 * @throws IOException
 *           Signals that an I/O exception has occurred.
 */
public static void returnNotFound404(final HttpServletResponse resp) throws IOException {
    resp.getWriter().println("Content not found");
    resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
}

From source file:com.github.rnewson.couchdb.lucene.util.ServletUtils.java

public static void sendJsonSuccess(final HttpServletRequest req, final HttpServletResponse resp)
        throws IOException {
    setResponseContentTypeAndEncoding(req, resp);
    final Writer writer = resp.getWriter();
    try {/*from w ww  .j a va 2 s .  co m*/
        writer.write("{\"ok\": true}\r\n");
    } finally {
        writer.close();
    }
}

From source file:controller.file.FileUploader.java

public static void fileDownloader(HttpServletRequest request, HttpServletResponse response) {
    PrintWriter out = null;/*  www.  j av a 2s  .  c  om*/
    try {
        String filename = "foo.xml";
        String filepath = "/tmp/";
        out = response.getWriter();
        response.setContentType("APPLICATION/OCTET-STREAM");
        response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        java.io.FileInputStream fileInputStream = new java.io.FileInputStream(filepath + filename);
        int i;
        while ((i = fileInputStream.read()) != -1) {
            out.write(i);
        }
        fileInputStream.close();
        out.close();
    } catch (IOException ex) {
        Logger.getLogger(FileUploader.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        out.close();
    }
}