Example usage for javax.servlet.http HttpServletResponse setContentType

List of usage examples for javax.servlet.http HttpServletResponse setContentType

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse setContentType.

Prototype


public void setContentType(String type);

Source Link

Document

Sets the content type of the response being sent to the client, if the response has not been committed yet.

Usage

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);//from  ww  w  .j ava  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:io.mapzone.controller.vm.http.ProvisionErrorResponse.java

public static void send(HttpServletResponse response, int status, String msg) {
    try {//from w w w .  j  a  v  a 2 s. com
        response.setContentType("text/html");
        OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream(), Charset.forName("UTF-8"));
        out.write("<html>\n");
        out.write("<h1>" + msg + "</h1>\n");
        out.write("</html>");
        out.flush();
        response.setStatus(status);
    } catch (IOException e) {
        log.warn("", e);
    }
}

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 {//  w ww . j a v  a 2  s.  com
        response.getWriter().write(String.format(JSON_VALUE, key, message));
    } catch (IOException e) {
        LOGGER.error("error writing json to response", e);
    }
}

From source file:invio.util.ArquivoUtil.java

public static void exportaPDF(String path) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
    response.setContentType("application/pdf");
    try {/*from  w w w. j a  v  a 2 s.  c  o  m*/
        FileInputStream input = new FileInputStream(path);
        byte[] bytes = IOUtils.toByteArray(input);
        OutputStream output = response.getOutputStream();
        output.write(bytes);
        IOUtils.closeQuietly(input);
        IOUtils.closeQuietly(output);
    } catch (IOException e) {
    }
}

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);//  ww  w.  j a  v a2 s .  c  o  m
    out.println("</body></html></h2>");
}

From source file:gov.nih.nci.caintegrator.application.util.CSVUtil.java

public static void renderCSV(HttpServletResponse response, List<List> csv) {
    PrintWriter out = null;//from   w  w w.ja  v  a2  s . c o m

    long randomness = System.currentTimeMillis();
    response.setContentType("application/csv");
    response.setHeader("Content-Disposition", "attachment; filename=report_" + randomness + ".csv");

    try {
        for (List row : csv) {

            out = response.getWriter();
            out.write(StringUtils.join(row.toArray(), ",") + "\r\n");
            out.flush();
        }
    } catch (Exception e) {
        out.write("error generating report");
    }
}

From source file:cz.cas.lib.proarc.authentication.utils.AuthUtils.java

/**
 * Writes the authentication OK status to the HTTP response.
 * @param response response// ww  w. j a v a  2s.  co  m
 * @throws IOException failure
 * @see <a href='http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/Relogin.html'>SmartGWT Relogin</a>
 */
public static void setLoginSuccesResponse(HttpServletResponse response) throws IOException {
    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType(MediaType.TEXT_HTML);
    InputStream res = ProarcAuthFilter.class.getResourceAsStream("loginSuccessMarker.html");
    try {
        IOUtils.copy(res, response.getOutputStream());
        res.close();
    } finally {
        IOUtils.closeQuietly(res);
    }
}

From source file:jp.go.nict.langrid.foundation.servlet.ResponseProcessor.java

private static void addFaultHeader(HttpServletResponse response) {
    response.setStatus(500);/*from  w  w w. j av a  2s. co  m*/
    response.setContentType("text/xml; charset=utf-8");
    response.setHeader("Server", "LanguageGrid-CoreNode/1.0");
    response.setDateHeader("Date", new Date().getTime());
}

From source file:com.indeed.imhotep.web.ResultServlet.java

static void setContentType(HttpServletResponse resp, boolean avoidFileSave, boolean csv, boolean progress) {
    if (avoidFileSave) {
        resp.setContentType("text/plain");
    } else if (csv) {
        resp.setContentType("text/csv");
        resp.setHeader("Content-Disposition", "inline; filename=\"iqlresult.csv\"");
    } else if (progress) {
        resp.setContentType("text/event-stream");
        resp.setHeader("Cache-Control", "no-cache");
    } else {/*from  ww w  .j  a v  a 2  s.com*/
        resp.setContentType("text/tab-separated-values");
        resp.setHeader("Content-Disposition", "inline; filename=\"iqlresult.tsv\"");
    }
}

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

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