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:io.hawt.testing.env.builtin.NotFound.java

@Override
public void handle(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
    resp.setContentType("application/json");
    resp.setCharacterEncoding("UTF-8");
    JSONObject r = new JSONObject();
    r.put("error", HttpServletResponse.SC_NOT_FOUND);
    r.put("message", "Environment not found");
    resp.getWriter().println(r.toJSONString());
    resp.getWriter().close();//  ww w  .  jav a2  s  .  c om
}

From source file:cn.featherfly.web.spring.servlet.view.json.ObjectJacksonJsonView.java

@Override
protected void prepareResponse(HttpServletRequest request, HttpServletResponse response) {
    setResponseContentType(request, response);
    response.setCharacterEncoding(this.getEncoding().getJavaName());
    if (cacheExpires > 0) {
        response.addHeader("Cache-Control", "max-age=" + cacheExpires);
    } else {//  w ww . j  ava  2 s. com
        response.addHeader("Pragma", "no-cache");
        response.addHeader("Cache-Control", "no-cache, no-store, max-age=0");
        response.addDateHeader("Expires", 1L);
    }
}

From source file:com.curl.orb.servlet.InstanceManagementServlet.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/octet-stream; charset=\"UTF-8\"");
}

From source file:net.proest.librepilot.web.handler.DefinitionHandler.java

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setCharacterEncoding("utf-8");
    response.setStatus(HttpServletResponse.SC_OK);

    PrintWriter out = response.getWriter();

    List<String> targetObjects = Arrays.asList(target.split("/"));

    SortedMap<String, UAVTalkXMLObject> objects = new TreeMap<>();

    for (UAVTalkXMLObject xmlObj : mFcDevice.getObjectTree().getXmlObjects().values()) {
        if (targetObjects.size() == 0 || targetObjects.contains(xmlObj.getName())) {
            if (mShowSettings && xmlObj.isSettings() || mShowState && !xmlObj.isSettings()) {
                objects.put(xmlObj.getName(), xmlObj);
            }/*from  w  w  w.  j a v a 2  s.co m*/
        }
    }

    String callback = request.getParameter("callback");

    if (callback != null) {
        response.setContentType("application/javascript");
        out.println(callback + "(");
    } else {
        response.setContentType("application/json");
    }

    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);

    out.println(mapper.writeValueAsString(objects));

    if (callback != null) {
        out.print(")");
    }

    baseRequest.setHandled(true);
}

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

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

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

    if (acnList != null) {
        StringBuilder result = new StringBuilder();
        result.append("<?xml version='1.0' encoding='ISO-8859-1'?><response>");
        for (AutocompleteNode sp : acnList) {
            result.append("<node><id>" + sp.getItemId() + "</id>");
            result.append("<name>" + sp.getItemName() + "</name></node>");
        }/* w  w  w  .j a  v a  2  s .c o m*/
        result.append("</response>");
        out.println(result.toString());
    }

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

    return null;
}

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

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

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

    StringBuilder result = new StringBuilder();
    result.append("<?xml version='1.0' encoding='ISO-8859-1'?><response><specimens>");

    for (Specimen s : specimens) {
        result.append("<specimen><scientificname>" + s.getScientificname() + "</scientificname>" + "<longitude>"
                + s.getDecimallongitude() + "</longitude>" + "<catalog>" + s.getCatalognumber() + "</catalog>"
                + "<institution>" + s.getInstitutioncode() + "</institution>" + "<latitude>"
                + s.getDecimallatitude() + "</latitude></specimen>");
    }/*  ww w .j  a v  a  2  s .c  o m*/
    result.append("</specimens></response>");

    out.println(result.toString());
    out.flush();
    out.close();

    return null;
}

From source file:br.com.munif.ffjma.FreeFormApi.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    System.out.println(getCollection(req));

    resp.setCharacterEncoding("UTF-8");

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("mensagem", "ola mundo!");

    mapper.writeValue(resp.getOutputStream(), map);
    resp.getOutputStream().close();//from w w w  .  j a v a2s. co  m

}

From source file:ru.mystamps.web.controller.SitemapController.java

@GetMapping(Url.SITEMAP_XML)
public void getSitemapXml(HttpServletResponse response) {
    response.setContentType("application/xml");
    response.setCharacterEncoding("UTF-8");

    DateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);

    try {/*ww w  . j a  v a2  s.  c om*/
        PrintWriter writer = response.getWriter();

        writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        writer.println("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");

        writer.print("\t<url>\t\t<loc>");
        writer.print(Url.PUBLIC_URL);
        writer.print(Url.INDEX_PAGE);
        writer.println("</loc>\t</url>");

        for (SitemapInfoDto item : seriesService.findAllForSitemap()) {
            writer.println("\t<url>");

            writer.print("\t\t<loc>");
            writer.print(createLocEntry(item));
            writer.println("</loc>");

            writer.print("\t\t<lastmod>");
            writer.print(createLastModEntry(dateFormatter, item));
            writer.println("</lastmod>");

            writer.println("\t</url>");
        }

        writer.println("</urlset>");
    } catch (IOException ex) {
        LOG.error("Can't return sitemap.xml: {}", ex.getMessage());
    }
}

From source file:com.ibm.ws.lars.rest.FrontPage.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType(MediaType.APPLICATION_JSON);
    resp.setCharacterEncoding(StandardCharsets.UTF_8.name());
    PrintWriter printWriter = resp.getWriter();

    List<AssetFilter> filters = new ArrayList<>();
    filters.add(new AssetFilter("state",
            Arrays.asList(new Condition[] { new Condition(Operation.EQUALS, "published") })));
    int assetCount = serviceLayer.countAllAssets(filters, null);

    JsonGenerator frontPageJsonGenerator = new JsonFactory().createGenerator(printWriter);
    frontPageJsonGenerator.setPrettyPrinter(new DefaultPrettyPrinter());

    frontPageJsonGenerator.writeStartObject();
    frontPageJsonGenerator.writeStringField("serverName", "LARS");
    frontPageJsonGenerator.writeNumberField("assetCount", assetCount);
    frontPageJsonGenerator.writeEndObject();

    frontPageJsonGenerator.flush();/* w w  w. j  av  a2s .co  m*/
    frontPageJsonGenerator.close();
}

From source file:org.jasig.portlet.calendar.mvc.EmptyView.java

@Override
protected void prepareResponse(HttpServletRequest request, HttpServletResponse response) {
    response.setContentType(getContentType());
    response.setCharacterEncoding(encoding.getJavaName());
}