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:cn.leancloud.diamond.server.controller.AdminController.java

@RequestMapping(params = "method=updateConfig", method = RequestMethod.POST)
public String updateConfig(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("dataId") String dataId, @RequestParam("group") String group,
        @RequestParam("content") String content, ModelMap modelMap) {
    response.setCharacterEncoding("UTF-8");

    ConfigInfo configInfo = new ConfigInfo(dataId, group, content);
    boolean checkSuccess = true;
    String errorMessage = "?";
    if (StringUtils.isBlank(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) {
        checkSuccess = false;/*  www  .  ja  v  a2s . co m*/
        errorMessage = "DataId";
    }
    if (StringUtils.isBlank(group) || DiamondUtils.hasInvalidChar(group.trim())) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (StringUtils.isBlank(content)) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!checkSuccess) {
        modelMap.addAttribute("message", errorMessage);
        modelMap.addAttribute("configInfo", configInfo);
        return "/admin/config/edit";
    }

    this.configService.updateConfigInfo(dataId, group, content);

    modelMap.addAttribute("message", "???!");
    return listConfig(request, response, dataId, group, 1, 20, modelMap);
}

From source file:com.taobao.diamond.server.controller.AdminController.java

@RequestMapping(params = "method=updateConfig", method = RequestMethod.POST)
public String updateConfig(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("dataId") String dataId, @RequestParam("group") String group,
        @RequestParam("content") String content, ModelMap modelMap) {
    response.setCharacterEncoding("GBK");

    ConfigInfo configInfo = new ConfigInfo(dataId, group, content);
    boolean checkSuccess = true;
    String errorMessage = "";
    if (StringUtils.isBlank(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) {
        checkSuccess = false;/*from   w w  w.j av  a 2  s  .  c  o  m*/
        errorMessage = "DataId";
    }
    if (StringUtils.isBlank(group) || DiamondUtils.hasInvalidChar(group.trim())) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (StringUtils.isBlank(content)) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!checkSuccess) {
        modelMap.addAttribute("message", errorMessage);
        modelMap.addAttribute("configInfo", configInfo);
        return "/admin/config/edit";
    }

    this.configService.updateConfigInfo(dataId, group, content);

    modelMap.addAttribute("message", "!");
    return listConfig(request, response, dataId, group, 1, 20, modelMap);
}

From source file:cn.leancloud.diamond.server.controller.AdminController.java

@RequestMapping(params = "method=postConfig", method = RequestMethod.POST)
public String postConfig(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("dataId") String dataId, @RequestParam("group") String group,
        @RequestParam("content") String content, ModelMap modelMap) {
    response.setCharacterEncoding("UTF-8");

    boolean checkSuccess = true;
    String errorMessage = "?";
    if (StringUtils.isBlank(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) {
        checkSuccess = false;//from   ww  w . j  ava2s.c om
        errorMessage = "DataId";
    }
    if (StringUtils.isBlank(group) || DiamondUtils.hasInvalidChar(group.trim())) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (StringUtils.isBlank(content)) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!checkSuccess) {
        modelMap.addAttribute("message", errorMessage);
        return "/admin/config/new";
    }

    dataId = dataId.trim();
    group = group.trim();

    this.configService.addConfigInfo(dataId, group, content);

    modelMap.addAttribute("message", "???!");
    return listConfig(request, response, dataId, group, 1, 20, modelMap);
}

From source file:com.mengka.diamond.server.controller.AdminController.java

@RequestMapping(params = "method=updateConfig", method = RequestMethod.POST)
public String updateConfig(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("dataId") String dataId, @RequestParam("group") String group,
        @RequestParam("content") String content, ModelMap modelMap) {
    response.setCharacterEncoding("utf-8");

    ConfigInfo configInfo = new ConfigInfo(dataId, group, content);
    boolean checkSuccess = true;
    String errorMessage = "?";
    if (StringUtils.isBlank(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) {
        checkSuccess = false;//from  w  ww . j  a v  a  2s  .  c  o m
        errorMessage = "DataId";
    }
    if (StringUtils.isBlank(group) || DiamondUtils.hasInvalidChar(group.trim())) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (StringUtils.isBlank(content)) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!checkSuccess) {
        modelMap.addAttribute("message", errorMessage);
        modelMap.addAttribute("configInfo", configInfo);
        return "/admin/config/edit";
    }

    this.configService.updateConfigInfo(dataId, group, content);

    modelMap.addAttribute("message", "???!");
    return listConfig(request, response, dataId, group, 1, 20, modelMap);
}

From source file:com.taobao.diamond.server.controller.AdminController.java

@RequestMapping(params = "method=postConfig", method = RequestMethod.POST)
public String postConfig(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("dataId") String dataId, @RequestParam("group") String group,
        @RequestParam("content") String content, ModelMap modelMap) {
    response.setCharacterEncoding("GBK");

    boolean checkSuccess = true;
    String errorMessage = "";
    if (StringUtils.isBlank(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) {
        checkSuccess = false;//from  w w  w .  j  av  a2 s.c o  m
        errorMessage = "DataId";
    }
    if (StringUtils.isBlank(group) || DiamondUtils.hasInvalidChar(group.trim())) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (StringUtils.isBlank(content)) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!checkSuccess) {
        modelMap.addAttribute("message", errorMessage);
        return "/admin/config/new";
    }

    dataId = dataId.trim();
    group = group.trim();

    this.configService.addConfigInfo(dataId, group, content);

    modelMap.addAttribute("message", "!");
    return listConfig(request, response, dataId, group, 1, 20, modelMap);
}

From source file:fi.mjpphotographs.bbqtemp.main.JsonHandler.java

/**
 * REturns commong configuration items (if no specific parameter is requested with request parameter cfgParamName)
 * @param response/*from   ww w  . ja v a2s. c  o m*/
 * @param request 
 */
private void getConfigData(HttpServletResponse response, HttpServletRequest request) {

    //TODO only selected item to config map..

    // collect common configs to this map and send it to client as json
    Map<String, String> commonCfg = new HashMap();
    commonCfg.put("max_temperature", bbqTempConfig.getString("max_temperature"));
    commonCfg.put("temperature_unit", bbqTempConfig.getString("temperature_unit"));

    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    try {
        response.getWriter().write(new Gson().toJson(commonCfg));
    } catch (IOException ex) {
        logger.error("Error while writing Configuration GSON to response.", ex);

    }

}

From source file:com.mengka.diamond.server.controller.AdminController.java

@RequestMapping(params = "method=postConfig", method = RequestMethod.POST)
public String postConfig(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("dataId") String dataId, @RequestParam("group") String group,
        @RequestParam("content") String content, ModelMap modelMap) {
    response.setCharacterEncoding("utf-8");

    boolean checkSuccess = true;
    String errorMessage = "?";
    if (StringUtils.isBlank(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) {
        checkSuccess = false;//  w w  w.  j a va  2  s  .c  om
        errorMessage = "DataId";
    }
    if (StringUtils.isBlank(group) || DiamondUtils.hasInvalidChar(group.trim())) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (StringUtils.isBlank(content)) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!checkSuccess) {
        modelMap.addAttribute("message", errorMessage);
        return "/admin/config/new";
    }

    dataId = dataId.trim();
    group = group.trim();

    this.configService.addConfigInfo(dataId, group, content);

    modelMap.addAttribute("message", "???!");
    return listConfig(request, response, dataId, group, 1, 20, modelMap);
}

From source file:com.github.jknack.handlebars.server.HbsServlet.java

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    Writer writer = null;//from ww w.  j  a  v  a  2 s.c o  m

    try {
        Template template = handlebars.compile(removeExtension(requestURI(request)));

        Object model = model(request);

        String output = template.apply(model);
        response.setCharacterEncoding(args.encoding);
        response.setContentType(args.contentType);
        writer = response.getWriter();
        writer.write(output);
    } catch (HandlebarsException ex) {
        handlebarsError(ex, response);
    } catch (JsonParseException ex) {
        logger.error("Unexpected error", ex);
        jsonError(ex, request, response);
    } catch (FileNotFoundException ex) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } catch (IOException ex) {
        logger.error("Unexpected error", ex);
        throw ex;
    } catch (RuntimeException ex) {
        logger.error("Unexpected error", ex);
        throw ex;
    } catch (Exception ex) {
        logger.error("Unexpected error", ex);
        throw new ServletException(ex);
    } finally {
        IOUtils.closeQuietly(writer);
    }
}

From source file:cn.leancloud.diamond.server.controller.AdminController.java

@RequestMapping(params = "method=upload", method = RequestMethod.POST)
public String upload(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("dataId") String dataId, @RequestParam("group") String group,
        @RequestParam("contentFile") MultipartFile contentFile, ModelMap modelMap) {
    response.setCharacterEncoding("UTF-8");

    boolean checkSuccess = true;
    String errorMessage = "?";
    if (StringUtils.isBlank(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) {
        checkSuccess = false;//from   w  w  w .  java 2  s  . c  o m
        errorMessage = "DataId";
    }
    if (StringUtils.isBlank(group) || DiamondUtils.hasInvalidChar(group.trim())) {
        checkSuccess = false;
        errorMessage = "";
    }
    String content = getContentFromFile(contentFile);
    if (StringUtils.isBlank(content)) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!checkSuccess) {
        modelMap.addAttribute("message", errorMessage);
        return "/admin/config/upload";
    }

    this.configService.addConfigInfo(dataId, group, content);
    modelMap.addAttribute("message", "???!");
    return listConfig(request, response, dataId, group, 1, 20, modelMap);
}

From source file:com.taobao.diamond.server.controller.AdminController.java

@RequestMapping(params = "method=upload", method = RequestMethod.POST)
public String upload(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("dataId") String dataId, @RequestParam("group") String group,
        @RequestParam("contentFile") MultipartFile contentFile, ModelMap modelMap) {
    response.setCharacterEncoding("GBK");

    boolean checkSuccess = true;
    String errorMessage = "";
    if (StringUtils.isBlank(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) {
        checkSuccess = false;/*from  w  w w.  j av  a 2 s  .  co m*/
        errorMessage = "DataId";
    }
    if (StringUtils.isBlank(group) || DiamondUtils.hasInvalidChar(group.trim())) {
        checkSuccess = false;
        errorMessage = "";
    }
    String content = getContentFromFile(contentFile);
    if (StringUtils.isBlank(content)) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!checkSuccess) {
        modelMap.addAttribute("message", errorMessage);
        return "/admin/config/upload";
    }

    this.configService.addConfigInfo(dataId, group, content);
    modelMap.addAttribute("message", "!");
    return listConfig(request, response, dataId, group, 1, 20, modelMap);
}