List of usage examples for javax.servlet.http HttpServletResponse setCharacterEncoding
public void setCharacterEncoding(String charset);
From source file:com.sccl.attech.common.web.BaseController.java
/** * ?response?//from w w w. j a va 2s . co m * * @param message * @throws IOException */ protected void sendObjectToJson(Object object, HttpServletResponse response) throws IOException { response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter pw = response.getWriter(); String message = JsonMapper.getInstance().toJson(object); pw.write(message); pw.flush(); pw.close(); }
From source file:cn.cug.laboratory.web.BaseController.java
/** * /* w w w. jav a 2s. co m*/ * @param response * @param string * @return */ protected String renderString(HttpServletResponse response, String string, String type) { try { response.reset(); response.setContentType(type); response.setCharacterEncoding("utf-8"); response.getWriter().print(string); return null; } catch (IOException e) { return null; } }
From source file:net.zcarioca.jmx.servlet.handlers.RestRequestHandler.java
public void respond(HttpServletRequest request, HttpServletResponse response) throws IOException { try {//from w w w. ja va 2 s .c o m Object value = getResponse(request); if (value != null) { response.setContentType(MediaType.APPLICATION_JSON); response.setCharacterEncoding("UTF-8"); BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(out, value); out.flush(); out.close(); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } } catch (InvalidObjectException exc) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); } catch (IOException exc) { throw exc; } catch (Exception exc) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.mirth.connect.server.servlets.EventServlet.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 .j av a2 s. c o m*/ try { EventController eventController = ControllerFactory.getFactory().createEventController(); ObjectXMLSerializer serializer = new ObjectXMLSerializer(); PrintWriter out = response.getWriter(); Operation operation = Operations.getOperation(request.getParameter("op")); String uid = null; boolean useNewTempTable = false; Map<String, Object> parameterMap = new HashMap<String, Object>(); if (StringUtils.isNotBlank(request.getParameter("uid"))) { uid = request.getParameter("uid"); useNewTempTable = true; } else { uid = request.getSession().getId(); } if (operation.equals(Operations.EVENT_CREATE_TEMP_TABLE)) { EventFilter eventFilter = (EventFilter) serializer.fromXML(request.getParameter("filter")); parameterMap.put("filter", eventFilter); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { response.setContentType(TEXT_PLAIN); out.println(eventController.createTempTable(eventFilter, uid, useNewTempTable)); } } else if (operation.equals(Operations.EVENT_REMOVE_FILTER_TABLES)) { if (!isUserAuthorized(request, null)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { eventController.removeFilterTable(uid); } } else if (operation.equals(Operations.EVENT_GET_BY_PAGE)) { if (!isUserAuthorized(request, null)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { int page = Integer.parseInt(request.getParameter("page")); int pageSize = Integer.parseInt(request.getParameter("pageSize")); int max = Integer.parseInt(request.getParameter("maxEvents")); response.setContentType(APPLICATION_XML); serializer.toXML(eventController.getEventsByPage(page, pageSize, max, uid), out); } } else if (operation.equals(Operations.EVENT_GET_BY_PAGE_LIMIT)) { EventFilter eventFilter = (EventFilter) serializer.fromXML(request.getParameter("filter")); parameterMap.put("filter", eventFilter); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { int page = Integer.parseInt(request.getParameter("page")); int pageSize = Integer.parseInt(request.getParameter("pageSize")); int max = Integer.parseInt(request.getParameter("maxEvents")); response.setContentType(APPLICATION_XML); serializer.toXML( eventController.getEventsByPageLimit(page, pageSize, max, uid, eventFilter), out); } } else if (operation.equals(Operations.EVENT_REMOVE_ALL)) { if (!isUserAuthorized(request, null)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { eventController.removeAllEvents(); // Audit after removal isUserAuthorized(request, null); } } else if (operation.equals(Operations.EVENT_EXPORT_ALL)) { if (!isUserAuthorized(request, null)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { response.setContentType(TEXT_PLAIN); out.println(eventController.exportAllEvents()); } } else if (operation.equals(Operations.EVENT_EXPORT_AND_REMOVE_ALL)) { if (!isUserAuthorized(request, null)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { response.setContentType(TEXT_PLAIN); // Add file path of export and audit after removal String exportPath = eventController.exportAndRemoveAllEvents(); parameterMap.put("file", exportPath); isUserAuthorized(request, parameterMap); out.println(exportPath); } } } catch (RuntimeIOException rio) { logger.debug(rio); } catch (Throwable t) { logger.error(ExceptionUtils.getStackTrace(t)); throw new ServletException(t); } } }
From source file:cn.vlabs.umt.ui.servlet.AppProxyServlet.java
private void sendRandom(HttpServletRequest request, HttpServletResponse response) throws IOException { RandomUtil ru = new RandomUtil(); String random = ru.getRandom(20); request.getSession().setAttribute("proxy_random", random); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.print(random);/*w w w. j av a 2s .c o m*/ out.flush(); out.close(); }
From source file:application.controllers.admin.EditEmotion.java
/** * lay du lieu truc tiep tu views list emotions de hien thi * * @param request//from ww w. j a va 2 s. c o m * @param response * @throws ServletException * @throws IOException */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("UTF-8"); response.addHeader("Content-Type", "text/html"); View layout = new View("Index.xtm"); View view = new View("admin", "EditEmotion.xtm"); TemplateDataDictionary listEmotionView = view.addSection("listEmotion"); //get list emotion in group String groupId = request.getParameter("groupId"); List<EmotionPOJO> listEmotionInGroup = (List<EmotionPOJO>) Memcached.get("listEmotionInGroup" + groupId); List<GroupEmotionPOJO> listGroupEmotion = (List<GroupEmotionPOJO>) Memcached.get("listGroupEmotion"); //get id from href location int indexEmotionSelected = Integer.parseInt(request.getParameter("id")); emotionSelected = listEmotionInGroup.get(indexEmotionSelected); //show image khong co trong database de add TemplateDataDictionary emotionItem = listEmotionView.addSection("emotionItem"); emotionItem.setVariable("imageId", Integer.toString(1)); emotionItem.setVariable("imageLink", listEmotionInGroup.get(indexEmotionSelected).linkImage); emotionItem.setVariable("descriptionEmotion", listEmotionInGroup.get(indexEmotionSelected).description); for (int i = 0; i < listGroupEmotion.size(); i++) { TemplateDataDictionary emotionSelect = emotionItem.addSection("emotionSelect"); emotionSelect.setVariable("groupEmotionId", Integer.toString(listGroupEmotion.get(i).id)); emotionSelect.setVariable("groupEmotionName", listGroupEmotion.get(i).name); } //Tao view String content = view.render(); layout.setVariable("content", content); //Tao view String resourceHost = ""; resourceHost += Registry.get("Host"); resourceHost = resourceHost + "/resources"; layout.setVariable("hostResource", resourceHost); String mainView = layout.render(); response.getWriter().write(mainView); }
From source file:net.duckling.ddl.web.controller.pan.PanDownloadController.java
private void sendPreviewDoc(String filename, long size, String remotePath, long version, HttpServletRequest request, HttpServletResponse response) { OutputStream os = null;/*from w w w .j a va 2s.c o m*/ long p0 = System.currentTimeMillis(); long tmpSize = size; try { response.setCharacterEncoding("utf-8"); String headerValue = ResponseHeaderUtils.buildResponseHeader(request, filename, true); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", headerValue); response.setContentLength((int) size); response.setHeader("Content-Length", tmpSize + ""); os = response.getOutputStream(); panService.download(PanAclUtil.getInstance(request), remotePath, version, os); } catch (UnsupportedEncodingException e) { LOG.error("", e); } catch (MeePoException e) { LOG.error("", e); } catch (IOException e) { LOG.error("", e); } catch (Exception e) { LOG.error("", e); } finally { IOUtils.closeQuietly(os); long p1 = System.currentTimeMillis(); LOG.info("Download document[name:" + filename + ",size:" + tmpSize + "] use time " + (p1 - p0)); } }
From source file:org.bonitasoft.web.designer.controller.PreviewController.java
/** * Returns fake css file for living app theme.css *//*from w w w .ja v a2 s . c o m*/ @RequestMapping("/preview/page/theme/theme.css") public void serveWidgetAsset(HttpServletResponse response) throws ServletException { response.setHeader("Content-Type", "text/css"); response.setHeader("Content-Disposition", "inline; filename=\"theme.css\""); response.setCharacterEncoding(StandardCharsets.UTF_8.toString()); response.setStatus(HttpStatus.OK.value()); try (PrintWriter writer = response.getWriter()) { writer.println("/**"); writer.println("* Living application theme"); writer.print("*/"); } catch (IOException e) { // fail silently } }
From source file:br.unicamp.cotuca.dpd.pd12.acinet.vagalmail.servlet.Configuracoes.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); String metodo = "", req = request.getRequestURI(); if (req.contains("/nova")) { metodo = "nova"; } else if (req.contains("/conta")) { metodo = "conta"; } else if (req.contains("/senha")) { metodo = "senha"; } else {/*from w w w . j av a 2s.co m*/ response.sendRedirect("/conf/conta"); } if (!"".equals(metodo)) request.getRequestDispatcher("/conf.jsp?metodo=" + metodo).include(request, response); }
From source file:io.getlime.security.powerauth.rest.api.spring.entrypoint.PowerAuthApiAuthenticationEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { PowerAuthApiResponse<String> errorResponse = new PowerAuthApiResponse<>("ERROR", "Authentication failed"); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.getOutputStream().println(new ObjectMapper().writeValueAsString(errorResponse)); response.getOutputStream().flush();//from www . java 2s .c o m }