Example usage for javax.servlet.http HttpServletResponse setCharacterEncoding

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

Introduction

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

Prototype

public void setCharacterEncoding(String charset);

Source Link

Document

Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.

Usage

From source file:it.unimi.di.big.mg4j.query.HelpPage.java

public Template handleRequest(final HttpServletRequest request, final HttpServletResponse response,
        final Context context) throws ResourceNotFoundException, ParseErrorException, Exception {
    response.setCharacterEncoding("UTF-8");
    return getTemplate("it/unimi/dsi/mg4j/query/help.velocity");
}

From source file:com.mitchellbosecke.pebble.spring.PebbleView.java

@Override
protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    response.setCharacterEncoding(this.characterEncoding);

    long startNanos = System.nanoTime();

    PebbleTemplate template = this.engine.getTemplate(this.templateName);

    // Add beans context
    model.put(BEANS_VARIABLE_NAME, new Beans(this.getApplicationContext()));

    // Add request & response
    model.put(REQUEST_VARIABLE_NAME, request);
    model.put(RESPONSE_VARIABLE_NAME, response);

    // Add session
    model.put(SESSION_VARIABLE_NAME, request.getSession(false));

    // Locale/*from  w  ww  .ja  v a 2s  .co m*/
    Locale locale = RequestContextUtils.getLocale(request);

    final Writer writer = response.getWriter();
    try {
        template.evaluate(writer, model, locale);
    } finally {
        writer.flush();
    }

    if (TIMER_LOGGER.isDebugEnabled()) {
        long endNanos = System.nanoTime();

        BigDecimal elapsed = BigDecimal.valueOf(endNanos - startNanos);
        BigDecimal elapsedMs = elapsed.divide(BigDecimal.valueOf(NANOS_IN_SECOND), RoundingMode.HALF_UP);
        TIMER_LOGGER.debug("Pebble template \"{}\" with locale {} processed in {} nanoseconds (approx. {}ms)",
                new Object[] { this.templateName, locale, elapsed, elapsedMs });
    }
}

From source file:com.suntek.gztpb.controller.ChangeContactControll.java

@RequestMapping(value = "success.htm", method = RequestMethod.POST)
public @ResponseBody String saveTest(DriverChangeModel driverInfo, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");
    PrintWriter out = response.getWriter();
    String applyNum = IdGenerator.getInstance().getBizCode("ITMS_SEQ", 5);

    driverInfo.setApplynum(applyNum);/*from  w  ww.  j  a v a  2  s .c  o  m*/
    System.out.println("applyNum=" + applyNum);

    driverInfo.setBiztype("3001");
    driverInfo.setCreatedtime(new Date());
    driverInfo.setCreator("admin");
    driverInfo.setSource(0);
    driverInfo.setSubmittime(new Date());
    driverInfo.setFinish(0);

    try {
        driverChangeService.signUp(driverInfo);
        out.write("<script>parent.saveCallback(1,'" + applyNum + "')</script>");
    } catch (Exception e) {
        e.printStackTrace();
        out.write("<script>parent.saveCallback(0)</script>");
    }
    return null;

}

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

@RequestMapping("/api/open-search")
public void openSearchServiceController(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    response.getWriter()/*from  w w  w . j  ava  2  s.c o m*/
            .write(OpenSearchService.parseHttpServletRequest(request, beanQueryModelFactory, launchProperties));
    response.getWriter().close();
}

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

@RequestMapping("/api/open-search.xml")
public void openSearchServiceDescriptionController(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(//from  w ww.  j av a2 s  . co m
            OpenSearchService.renderDescriptionDocument(request, beanQueryModelFactory, launchProperties));
    response.getWriter().close();
}

From source file:org.inbio.ait.web.ajax.controller.SelectAllController.java

private ModelAndView writeReponse(HttpServletRequest request, HttpServletResponse response, List<Polygon> pList)
        throws Exception {

    response.setCharacterEncoding("ISO-8859-1");
    response.setContentType("text/xml");
    // Binary output
    ServletOutputStream out = response.getOutputStream();

    if (pList != null) {
        StringBuilder result = new StringBuilder();
        result.append("<?xml version='1.0' encoding='ISO-8859-1'?><response>");
        for (Polygon p : pList) {
            result.append("<polygon><id>" + p.getId() + "</id>");
            result.append("<name>" + p.getName() + "</name></polygon>");
        }/*from ww  w  .j av a2 s.  co m*/
        result.append("</response>");
        out.println(result.toString());
    }

    out.flush();
    out.close();

    return null;
}

From source file:com.cognifide.aet.rest.ArtifactServlet.java

@Override
protected void process(DBKey dbKey, HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String id = req.getParameter(Helper.ID_PARAM);
    resp.setCharacterEncoding("UTF-8");
    Artifact artifact = artifactsDAO.getArtifact(dbKey, id);
    if (artifact != null) {
        resp.setContentType(artifact.getContentType());
        resp.setHeader("Cache-Control", "public, max-age=31536000");

        OutputStream output = resp.getOutputStream();
        IOUtils.copy(artifact.getArtifactStream(), output);
        output.flush();/*w  w  w.  j a  va 2s. c  o m*/
    } else {
        resp.setStatus(HttpURLConnection.HTTP_BAD_REQUEST);
        resp.setContentType("application/json");
        resp.getWriter()
                .write(responseAsJson("Unable to get artifact with id : %s form %s", id, dbKey.toString()));
    }
}

From source file:ca.uhn.fhir.rest.server.servlet.ServletRestfulResponse.java

@Override
public Writer getResponseWriter(int theStatusCode, String theStatusMessage, String theContentType,
        String theCharset, boolean theRespondGzip) throws UnsupportedEncodingException, IOException {
    addHeaders();// w  w w  .j av  a 2  s .  c  om
    HttpServletResponse theHttpResponse = getRequestDetails().getServletResponse();
    theHttpResponse.setCharacterEncoding(theCharset);
    theHttpResponse.setStatus(theStatusCode);
    theHttpResponse.setContentType(theContentType);
    if (theRespondGzip) {
        theHttpResponse.addHeader(Constants.HEADER_CONTENT_ENCODING, Constants.ENCODING_GZIP);
        return new OutputStreamWriter(new GZIPOutputStream(theHttpResponse.getOutputStream()),
                Constants.CHARSET_NAME_UTF8);
    } else {
        return theHttpResponse.getWriter();
    }
}

From source file:it.drwolf.ridire.servlet.TmpResourcesServlet.java

public void getTmpFile(String filename) {
    HttpServletResponse response = (HttpServletResponse) this.extCtx.getResponse();
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");
    try {// www. j av a2  s .  c om
        String ret = FileUtils.readFileToString(
                new File(
                        System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + filename),
                "UTF-8");
        response.getOutputStream().print(ret);
        response.getOutputStream().flush();
        // FacesContext.getCurrentInstance().responseComplete();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.intuit.tweetstest.TweetsController.java

protected void sendResponse(HttpServletResponse response, JSONObject result) throws IOException {
    response.setCharacterEncoding("UTF-8");
    String resultStr = result.toString();
    response.setContentType("application/json");
    response.getWriter().print(resultStr);
}