List of usage examples for javax.servlet.http HttpServletResponse setCharacterEncoding
public void setCharacterEncoding(String charset);
From source file:com.commercehub.dropwizard.BuildInfoServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setCharacterEncoding(StandardCharsets.UTF_8.name()); response.setHeader(HttpHeaders.CACHE_CONTROL, cacheControl.toString()); response.setStatus(HttpServletResponse.SC_OK); String requestedKey = getRequestedKey(request); if (StringUtils.isNotBlank(requestedKey)) { writeValueForKey(requestedKey, response); } else if (requestedHtml(request)) { writeAllHtml(response);// www.j a v a2 s .co m } else { writeAllJson(response); } }
From source file:com.jiangyifen.ec2.servlet.http.common.filter.HttpCommonFilter.java
/** * @Description ??????/*from w ww . j ava2 s .co m*/ * * @author JRH * @date 201488 ?12:43:21 * @param response HttpServletResponse * @param commonRespBo ?? * @throws IOException */ private void operateResponse(HttpServletResponse response, CommonRespBo commonRespBo) throws IOException { response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); response.setContentType("text/plain"); out.println("" + GsonUtil.toJson(commonRespBo)); out.close(); }
From source file:org.inbio.ait.web.ajax.controller.ExportCsvController.java
private ModelAndView writeReponse(HttpServletRequest request, HttpServletResponse response, List<Specimen> specimens) throws Exception { response.setCharacterEncoding("ISO-8859-1"); response.setContentType("text/html"); ServletOutputStream out = response.getOutputStream(); //String documento = ""; StringBuilder documento = new StringBuilder(); documento.append(//from ww w . ja v a 2 s .c o m "<table class=\"contacts\" cellspacing=\"0\"><tr><th class=\"species\">Nombre cientfico</th><th class=\"species\">Longitud</th><th class=\"species\">Latitud</th><th class=\"species\"># de catlogo</th><th class=\"species\">Institucin</th>"); for (Specimen s : specimens) { documento.append("<tr>"); documento.append("<td class=\"contact\">" + s.getScientificname() + "</td>"); documento.append("<td class=\"contact\">" + s.getDecimallongitude() + "</td>"); documento.append("<td class=\"contact\">" + s.getDecimallatitude() + "</td>"); documento.append("<td class=\"contact\">" + s.getCatalognumber() + "</td>"); documento.append("<td class=\"contact\">" + s.getInstitutioncode() + "</td>"); documento.append("<tr>"); } documento.append("</table>"); out.println(documento.toString()); out.flush(); out.close(); return null; }
From source file:de.unirostock.sems.cbarchive.web.servlet.IconServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException { // set charset response.setCharacterEncoding(Fields.CHARSET); request.setCharacterEncoding(Fields.CHARSET); // splitting request URL String requestUrl = request.getRequestURI(); LOGGER.debug("IconServlet request: ", requestUrl); if (requestUrl != null && !requestUrl.isEmpty()) { String formatString = null; try {//from w w w.ja v a2 s . c o m response.setContentType("image/png"); formatString = requestUrl.substring(requestUrl.indexOf("res/icon/") + 9); LOGGER.debug("format: ", formatString); URI format = new URI(formatString); LOGGER.debug("format url: ", format); OutputStream output = response.getOutputStream(); InputStream input = Iconizer.formatToIconStream(format); int size = IOUtils.copy(input, output); response.setContentLength(size); output.flush(); output.close(); input.close(); response.flushBuffer(); } catch (IOException e) { LOGGER.error(e, "IOException while loading icon"); } catch (URISyntaxException e) { LOGGER.warn(e, "Not able to generate URL for Iconizer: ", formatString); } } }
From source file:org.mitre.openid.connect.view.JsonEntityView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) { response.setContentType(MediaType.APPLICATION_JSON_VALUE); response.setCharacterEncoding("UTF-8"); HttpStatus code = (HttpStatus) model.get(HttpCodeView.CODE); if (code == null) { code = HttpStatus.OK; // default to 200 }/* w w w . ja v a 2s . c o m*/ response.setStatus(code.value()); try { Writer out = response.getWriter(); Object obj = model.get(ENTITY); gson.toJson(obj, out); } catch (IOException e) { logger.error("IOException in JsonEntityView.java: ", e); } }
From source file:org.craftercms.core.util.spring.mvc.GsonView.java
@Override protected void prepareResponse(HttpServletRequest request, HttpServletResponse response) { response.setContentType(getContentType()); response.setCharacterEncoding(DEFAULT_CHARACTER_ENCODING); if (disableCaching) { HttpServletUtils.disableCaching(response); }/* w w w. j a v a 2s . c o m*/ }
From source file:com.mirth.connect.server.servlets.ChannelStatisticsServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // MIRTH-1745 response.setCharacterEncoding("UTF-8"); if (!isUserLoggedIn(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } else {/*from w w w. ja v a2 s . c om*/ try { ChannelStatisticsController statisticsController = ControllerFactory.getFactory() .createChannelStatisticsController(); ObjectXMLSerializer serializer = new ObjectXMLSerializer(); PrintWriter out = response.getWriter(); Operation operation = Operations.getOperation(request.getParameter("op")); String channelId = request.getParameter("id"); Map<String, Object> parameterMap = new HashMap<String, Object>(); parameterMap.put("channelId", channelId); if (operation.equals(Operations.CHANNEL_STATS_GET)) { if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { response.setContentType(APPLICATION_XML); serializer.toXML(statisticsController.getStatistics(channelId), out); } } else if (operation.equals(Operations.CHANNEL_STATS_CLEAR)) { if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { boolean deleteReceived = Boolean.valueOf(request.getParameter("deleteReceived")); boolean deleteFiltered = Boolean.valueOf(request.getParameter("deleteFiltered")); boolean deleteQueued = Boolean.valueOf(request.getParameter("deleteQueued")); boolean deleteSent = Boolean.valueOf(request.getParameter("deleteSent")); boolean deleteErrored = Boolean.valueOf(request.getParameter("deleteErrored")); boolean deleteAlerted = Boolean.valueOf(request.getParameter("deleteAlerted")); statisticsController.clearStatistics(channelId, deleteReceived, deleteFiltered, deleteQueued, deleteSent, deleteErrored, deleteAlerted); } } } catch (RuntimeIOException rio) { logger.debug(rio); } catch (Throwable t) { logger.error(ExceptionUtils.getStackTrace(t)); throw new ServletException(t); } } }
From source file:flexus.web.servlet.StartMenusServlet.java
/** * @param request//ww w . j ava 2s . c o m * @param response */ private void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding(charsetName); response.setCharacterEncoding(charsetName); InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("startMenus.xml"); byte[] bytes = null; if (stream != null && stream.available() > 0) { bytes = IOUtils.toByteArray(stream); } response.setContentType("text/xml"); if (bytes != null) { response.getOutputStream().write(bytes); response.getOutputStream().flush(); } }
From source file:elw.miniweb.ViewJackson.java
public void render(Map model, HttpServletRequest request, HttpServletResponse resp) throws Exception { resp.setContentType(getContentType() + "; charset=UTF-8"); resp.setCharacterEncoding("UTF-8"); resp.setHeader("Pragma", "no-cache"); resp.setHeader("Cache-Control", "no-cache"); resp.setDateHeader("Expires", System.currentTimeMillis()); MAPPER.writeValue(resp.getWriter(), stateOrData); }
From source file:com.aurel.track.dbase.ReadyTesterServlet.java
private void prepareResponse(HttpServletResponse httpServletResponse) { try {//from ww w. j av a2 s . c o m httpServletResponse.reset(); httpServletResponse.setCharacterEncoding("UTF-8"); } catch (Exception e) { //when the <s:action/> is present on the jsp //(mainly getting root nodes the same response object is used, and second time it can't be reseted) } httpServletResponse.setContentType("application/json"); }