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:com.suntek.gztpb.controller.ChemicalController.java

@RequestMapping(value = "saveApply.htm", method = RequestMethod.POST)
public @ResponseBody String saveApply(ChemicalModel chemcial, HttpServletRequest request,
        HttpServletResponse response) throws ServiceException, IOException {

    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/html");
    Timestamp now = null;//  w  ww  .  ja va 2s  .  co m
    PrintWriter out = response.getWriter();
    try {

        now = new Timestamp(System.currentTimeMillis());
        String applyNum = IdGenerator.getInstance().getBizCode("ITMS_SEQ", 5);
        chemcial.setApplyNum(applyNum);
        chemcial.setBizType("0401"); //0401  ????
        chemcial.setApplyTime(now);
        String line = request.getParameter("beginLine") + "" + request.getParameter("finishLine");
        chemcial.setLine(line);
        Timestamp goBeginTime = CommonUtil.parseToTimestamp("yyyy-MM-dd HH:mm:ss",
                request.getParameter("beginTime").trim());
        Timestamp goFinishTime = CommonUtil.parseToTimestamp("yyyy-MM-dd HH:mm:ss",
                request.getParameter("finishTime").trim());
        chemcial.setGoBeginTime(goBeginTime);
        chemcial.setGoFinishTime(goFinishTime);

        chemcial.setSource(0);//??0   gztpb;9   ; 
        chemcial.setCreator("admin");
        chemcial.setCreatedTime(now);
        chemcial.setSubmiTime(now);
        chemcial.setFinish(0);
        chemicalService.signUp(chemcial);
        out.write("<script>parent.saveCallback('1','" + applyNum + "');</script>");
    } catch (Exception e1) {
        System.out.println(
                "[gztpbwebsite]ChemicalController.saveApply,?????"
                        + e1.getMessage());
        out.write("<script>parent.saveCallback('0');</script>");

    }

    return null;
}

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

@RequestMapping(value = "saveApply.htm", method = RequestMethod.POST)
public String saveApply(DriverLicenseModel apply, HttpServletRequest request, HttpServletResponse response)
        throws ServiceException, IOException {
    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");
    PrintWriter out = response.getWriter();
    try {//w w w . j  a v  a 2s .c  o m
        String applyNum = IdGenerator.getInstance().getBizCode("ITMS_SEQ", 5);
        apply.setApplyNum(applyNum);
        driverLicenseService.saveApply(apply);
        out.write("<script>parent.saveCallback(1,'" + applyNum + "')</script>");
    } catch (Exception e) {
        logger.error(e.getMessage());
        out.write("<script>parent.saveCallback(0)</script>");
    }

    return null;
}

From source file:io.neba.core.resourcemodels.metadata.ModelMetadataConsolePlugin.java

private void prepareJsonResponse(HttpServletResponse res) {
    res.setCharacterEncoding("UTF-8");
    res.setContentType("application/json; charset=UTF-8");
}

From source file:io.fabric8.apiman.ui.TranslationServlet.java

/**
 *  @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *      //from  w  w w  .j  a  va2s  . c  o  m
 * Returns the UI strings specific to fabric8, stored in f8-translations.js.
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    InputStream is = getClass().getResourceAsStream("/apimanui/apiman/f8-translations.js");
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/javascript");
    try {
        byte[] buffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = is.read(buffer)) != -1) {
            response.getOutputStream().write(buffer, 0, bytesRead);
        }
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:com.gae.ChannelAPIServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setCharacterEncoding("utf-8");
    String clientInfo = req.getParameter("clientId");
    String clientId = "";
    int durationMinutes = 0;
    if (clientInfo.indexOf(":") != -1) {
        clientId = (String) clientInfo.split(":")[0];
        String dminutes1 = (String) clientInfo.split(":")[1];
        durationMinutes = Integer.parseInt(dminutes1.substring(0, dminutes1.length() - 1));
    } else {//  www .  j a va2s  .c  o  m
        clientId = new String(clientInfo);
        durationMinutes = 0;
    }
    String action = req.getParameter("action");
    if (action.equals("open")) {
        String token = "";
        try {
            if (durationMinutes > 0) {
                token = channelService.createChannel(clientId, durationMinutes);
            } else {
                token = channelService.createChannel(clientId);
            }
        } catch (ChannelFailureException e) {
            throw new RuntimeException(e);
        }
        String clientList = "";
        try {
            byte[] clientList_b = (byte[]) cache.get("uidKey");
            clientList = new String(clientList_b, "UTF-8");
        } catch (Exception e) {
        }
        clientList += clientId + ",";
        byte[] clientList_bn = clientList.getBytes("UTF-8");
        cache.put("uidKey", clientList_bn);
        resp.setContentType("text/plain");
        resp.setCharacterEncoding("utf-8");
        resp.getWriter().write(token);
    } else if (action.equals("close")) {
        byte[] clientList_b = (byte[]) cache.get("uidKey");
        String clientList = new String(clientList_b, "UTF-8");
        String[] clientList_a = clientList.split(",");
        String clientList_n = "";
        for (int i = 0; i < clientList_a.length; i++) {
            if (!clientId.equals(clientList_a[i])) {
                clientList_n += clientList_a[i] + ",";
            }
        }
        byte[] clientList_bn = clientList_n.getBytes("UTF-8");
        cache.put("uidKey", clientList_bn);
        resp.getWriter().write(clientList_n);
    } else if (action.equals("cinit")) {
        String init = clientId + ",";
        byte[] init_b = init.getBytes("UTF-8");
        cache.put("uidKey", init_b);
        resp.getWriter().write("IDclientId?????");
    }
}

From source file:gumga.framework.presentation.push.GumgaNotificationsServlet.java

@RequestMapping("/notifications/source")
protected void notifications(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/event-stream");
    response.setCharacterEncoding("UTF-8");
    PrintWriter writer = response.getWriter();
    QueryObject qo = new QueryObject();
    qo.setAq("destinationLogin='" + GumgaThreadScope.login.get() + "' and viewedIn is null ");
    qo.setAq("viewedIn is null ");
    qo.setPageSize(1000);/*ww  w  .  j a va 2s  . c  o  m*/

    for (int i = 0; i < cycles; i++) {
        SearchResult<GumgaMessage> pesquisa = messageService.pesquisa(qo);
        String message = "data: {" + " \"newMessagesCount\":" + pesquisa.getCount() + ",\"newMessages\":"
                + pesquisa.getValues() + "}";
        writer.write(message + "\n\n");
        writer.flush();
        try {
            Thread.sleep(intervalTime);
        } catch (InterruptedException e) {
            log(e.getMessage());
        }
    }
    writer.close();
}

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

@RequestMapping(value = "saveApply.htm", method = RequestMethod.POST)
public String saveApply(VehicleLicenseModel apply, HttpServletRequest request, HttpServletResponse response)
        throws ServiceException, IOException {
    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");
    PrintWriter out = response.getWriter();
    try {//from   w  w  w  . j ava 2  s. c o  m
        String picPath = this.servletContext.getRealPath("/picUpload/") + "\\";
        String applyNum = IdGenerator.getInstance().getBizCode("ITMS_SEQ", 5);
        apply.setApplyNum(applyNum);

        byte[] fileStream = CommonUtil.getFileByte(picPath + apply.getVehicleImage());
        vehicleLicenseService.saveApply(apply, fileStream);
        out.write("<script>parent.saveCallback(1,'" + applyNum + "')</script>");
    } catch (Exception e) {
        logger.error(e.getMessage());
        out.write("<script>parent.saveCallback(0)</script>");
    }

    return null;
}

From source file:de.perdian.apps.dashboard.mvc.portal.PortalView.java

@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");

    PrintWriter printWriter = response.getWriter();
    printWriter.append("<!DOCTYPE html>\n");
    printWriter.append("<html>\n");
    printWriter.append("<head>\n");
    this.appendDashboardHead(model, request, response);
    printWriter.append("</head>\n");
    printWriter.append("<body>\n");
    this.appendDashboardBody(model, request, response);
    printWriter.append("</body>\n");
    printWriter.append("</html>\n");

}

From source file:webcomicreader.webapp.controller.BackupRestoreController.java

/**
 * Downloads the entire contents of the database in a json format.
 *///from   w ww . ja v  a 2  s.co m
@RequestMapping(value = "/dumpdb", method = RequestMethod.GET)
public void dumpDatabase(HttpServletResponse response) throws IOException {
    String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm").format(new Date());
    String dumpdbStr = storage.dumpdb();
    response.setCharacterEncoding("UTF-8");
    response.setHeader("Content-Disposition", "attachment; filename=dumpdb_" + dateStr + ".json");
    response.setContentType("application/json");
    response.getWriter().write(dumpdbStr);
}

From source file:flexus.web.servlet.APListServlet.java

/**
 * {@inheritDoc}//from w  w w.j  a  v a  2s  .  com
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    response.setContentType("text/xml");
    response.setCharacterEncoding("utf-8");

    InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("aps.xml");

    if (stream != null) {
        try {
            String apDoc = IOUtils.toString(stream, "UTF-8");
            if (apDoc != null && apDoc.trim().length() > 0) {
                response.getWriter().write(apDoc);
            }
        } finally {
            response.getWriter().flush();
            IOUtils.closeQuietly(stream);
        }
    }
}