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.jasig.cas.support.oauth.OAuthUtils.java

/**
 * Write to the output the text and return a null view.
 *
 * @param response http response/* w ww  .  j  ava 2 s .c  o  m*/
 * @param text output text
 * @param status status code
 * @return a null view
 */
public static ModelAndView writeText(final HttpServletResponse response, final String text, final int status) {
    try (PrintWriter printWriter = response.getWriter()) {
        response.setStatus(status);
        printWriter.print(text);
    } catch (final IOException e) {
        LOGGER.error("Failed to write to response", e);
    }
    return null;
}

From source file:net.shopxx.util.JsonUtil.java

/**
 * ?JSON?/*from  w w w  .ja  va2s. c om*/
 * @param response HttpServletResponse
 * @param object 
 */
public static void toJson(HttpServletResponse response, Object value) {
    Assert.notNull(response);
    Assert.notNull(value);
    try {
        mapper.writeValue(response.getWriter(), value);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.hj2eplatform.core.component.CustomAuthenticationSuccessHandler.java

public static void sendJsonResponse(HttpServletResponse response, String key, String message) {
    response.setContentType("application/json;charset=UTF-8");
    response.setHeader("Cache-Control", "no-cache");
    try {/*from w w w  .j  av  a 2 s . co  m*/
        response.getWriter().write(String.format(JSON_VALUE, key, message));
    } catch (IOException e) {
        LOGGER.error("error writing json to response", e);
    }
}

From source file:com.claresco.tinman.servlet.XapiServletUtility.java

protected static PrintWriter getWriter(HttpServletResponse resp) throws XapiServletOperationProblemException {
    try {/*from w w w  .j  av a  2 s. com*/
        return resp.getWriter();
    } catch (IOException e) {
        throw new XapiServletOperationProblemException("Having problem writing a response");
    }
}

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

public static void sendJson(final HttpServletRequest req, final HttpServletResponse resp, final JSONObject json)
        throws IOException {
    setResponseContentTypeAndEncoding(req, resp);
    final Writer writer = resp.getWriter();
    try {/*from  ww w . ja v a 2 s  .co  m*/
        writer.write(json.toString() + "\r\n");
    } finally {
        writer.close();
    }
}

From source file:com.twitter.ambrose.server.ScriptStatusServer.java

private static void sendJson(HttpServletRequest request, HttpServletResponse response, Object object)
        throws IOException {
    JSONUtil.writeJson(response.getWriter(), object);
    response.getWriter().close();//from  ww  w .ja va  2  s. co  m
    setHandled(request);
}

From source file:myproject.MyServer.java

public static void List(HttpServletRequest request, HttpServletResponse response) throws IOException {
    try {/*from   w w  w.  ja v a 2 s.c om*/
        String query = "SELECT * FROM student";
        String result = database.runQuery(query);
        response.getWriter().write(result);
    } catch (Exception ex) {
        JSONObject output = new JSONObject();
        output.put("error", "Connection failed: " + ex.getMessage());
        response.getWriter().write(JSONValue.toJSONString(output));
    }
}

From source file:com.google.caja.ancillary.servlet.UploadPage.java

private static void writeHeader(HttpServletResponse resp) throws IOException {
    resp.setStatus(200);/*w w  w.  j av a  2  s .  c o m*/
    resp.setContentType("text/html;charset=UTF-8");
    Writer out = resp.getWriter();
    out.write("<h1>Loading&hellip;</h1>");
    out.flush();
}

From source file:br.eb.ime.pfc.domain.GeoServerCommunication.java

private static void sendError(HTTP_STATUS status, HttpServletResponse response) {
    try (Writer writer = response.getWriter()) {
        response.sendError(status.getCode());
    } catch (IOException e) {
    }/* ww  w.j  a v a 2 s  .  co  m*/
}

From source file:com.tn.exam.util.web.springside.Struts2Utils.java

/**
 * .//from   w ww.  j a  va 2  s.  c o m
        
 * eg.
 * render("text/plain", "hello", "encoding:GBK");
 * render("text/plain", "hello", "no-cache:false");
 * render("text/plain", "hello", "encoding:GBK", "no-cache:false");
 * 
 * @param headers ??header??"encoding:""no-cache:",UTF-8true.
 */
public static void render(final String contentType, final String content, final String... headers) {
    HttpServletResponse response = initResponseHeader(contentType, headers);
    try {
        response.getWriter().write(content);
        response.getWriter().flush();
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}