List of usage examples for javax.servlet.http HttpServletResponse setCharacterEncoding
public void setCharacterEncoding(String charset);
From source file:de.kp.ames.web.core.service.ServiceImpl.java
public void sendErrorResponse(String content, int errorStatus, HttpServletResponse response) throws IOException { response.setStatus(errorStatus);// ww w . j av a 2s .c o m response.setCharacterEncoding(GlobalConstants.UTF_8); response.setContentType(GlobalConstants.MT_TEXT); byte[] bytes = content.getBytes(GlobalConstants.UTF_8); response.setContentLength(bytes.length); OutputStream os = response.getOutputStream(); os.write(bytes); os.close(); }
From source file:de.kp.ames.web.core.service.ServiceImpl.java
public void sendResponse(String content, String mimetype, HttpServletResponse response) throws IOException { response.setStatus(HttpServletResponse.SC_OK); response.setCharacterEncoding(GlobalConstants.UTF_8); response.setContentType(mimetype);//from ww w.ja v a 2 s . c o m byte[] bytes = content.getBytes(GlobalConstants.UTF_8); response.setContentLength(bytes.length); OutputStream os = response.getOutputStream(); os.write(bytes); os.close(); }
From source file:com.laxser.blitz.web.impl.thread.ActionEngine.java
private void applyHttpFeatures(final Invocation inv) throws UnsupportedEncodingException { HttpServletResponse response = inv.getResponse(); if (StringUtils.isNotBlank(httpFeatures.charset())) { response.setCharacterEncoding(httpFeatures.charset()); if (logger.isDebugEnabled()) { logger.debug("set response.characterEncoding by HttpFeatures:" + httpFeatures.charset()); }/* w ww . j a va 2 s . co m*/ } if (StringUtils.isNotBlank(httpFeatures.contentType())) { String contentType = httpFeatures.contentType(); if (contentType.equals("json")) { contentType = "application/json"; } else if (contentType.equals("xml")) { contentType = "text/xml"; } else if (contentType.equals("html")) { contentType = "text/html"; } else if (contentType.equals("plain") || contentType.equals("text")) { contentType = "text/plain"; } response.setContentType(contentType); if (logger.isDebugEnabled()) { logger.debug("set response.contentType by HttpFeatures:" + response.getContentType()); } } }
From source file:de.fau.amos4.web.PrintDataController.java
@RequestMapping("/employee/download/text") public ModelAndView EmployeeDownloadText(HttpServletResponse response, @RequestParam(value = "id", required = true) long employeeId) throws IOException { // Use the service to get the Employee in the LODAS format final String employeeAsLodas = employeeService.getLodasRepresentation(employeeId); if (employeeAsLodas == null) { return new ModelAndView("redirect:/client/dashboard"); }/*from w ww.j av a 2 s .co m*/ // We want to have a txt file download response.setContentType("text/plain"); response.setHeader("Content-Disposition", "attachment;filename=employee_as_lodas.txt"); response.setCharacterEncoding("UTF-8"); // Write the data out ServletOutputStream out = response.getOutputStream(); out.write(employeeAsLodas.getBytes()); out.flush(); out.close(); return null; }
From source file:net.cit.tetrad.resource.CommandResource.java
@RequestMapping("/runCommamd.do") public void loginView(HttpServletResponse response, CommonDto dto) throws Exception { Map<String, Object> serverStatusFromMongo = new HashMap<String, Object>(); serverStatusFromMongo = comandService.insertCommand(dto.getDeviceCode(), dto.getMemo()); List<Object> arrTotInfo = new ArrayList<Object>(); arrTotInfo.add(serverStatusFromMongo); PersonJson result = new PersonJson(); result.setAaData(arrTotInfo);//from www .j ava2 s.co m JSONObject jsonObject = JSONObject.fromObject(result); response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); response.setHeader("Cache-Control", "no-cache"); Writer writer = response.getWriter(); writer.write(jsonObject.toString()); writer.flush(); }
From source file:xx.tream.chengxin.ms.action.TrainReportAction.java
@RequestMapping({ "/exportReportDetail" }) public String exportReportDetail(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response, FormMap formMap) throws IOException { Map<String, Object> queryMap = formMap.getFormMap(); OutputStream os = response.getOutputStream(); response.reset();//from w ww. j a va2s.c o m response.setCharacterEncoding("UTF-8"); String title = "" + getDateFile() + ".xls"; response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(title, "UTF-8")); response.setContentType("application/vnd.ms-excel"); HSSFWorkbook workbook = new HSSFWorkbook(); this.reportService.financialStatementsDetail(workbook, queryMap); workbook.write(os); os.flush(); os.close(); return "train/exportReportDetail"; }
From source file:xx.tream.chengxin.ms.action.TrainReportAction.java
@RequestMapping({ "/exportReport" }) public String exportReport(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response, FormMap formMap) throws IOException { Map<String, Object> queryMap = formMap.getFormMap(); OutputStream os = response.getOutputStream(); response.reset();/*from w ww . j a v a 2 s.com*/ response.setCharacterEncoding("UTF-8"); String title = "" + getDateFile() + ".xls"; response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(title, "UTF-8")); response.setContentType("application/vnd.ms-excel"); HSSFWorkbook workbook = new HSSFWorkbook(); this.reportService.financialStatements(workbook, queryMap); workbook.write(os); os.flush(); os.close(); return "train/exportReport"; }
From source file:psiprobe.controllers.sql.QueryHistoryItemController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int sqlId = ServletRequestUtils.getIntParameter(request, "sqlId", -1); HttpSession sess = request.getSession(false); if (sess != null) { DataSourceTestInfo sessData = (DataSourceTestInfo) sess .getAttribute(DataSourceTestInfo.DS_TEST_SESS_ATTR); if (sessData != null) { List<String> queryHistory = sessData.getQueryHistory(); if (queryHistory != null) { try { String sql = queryHistory.get(sqlId); response.setCharacterEncoding(StandardCharsets.UTF_8.name()); response.getWriter().print(sql); } catch (IndexOutOfBoundsException e) { logger.error("Cannot find a query history entry for history item id = {}", sqlId); logger.trace("", e); }/*from ww w.j av a 2s . c o m*/ } } } return null; }
From source file:io.resthelper.RestHelperController.java
@RequestMapping(value = "/rest-helper/restfuljs", method = RequestMethod.GET) public void restfuljs(HttpServletRequest request, HttpServletResponse response) throws IOException { if (!restHelperService.isValidIp(request)) { throw new NotAllowIpException(); }//from w w w.java2 s .co m response.setContentType("text/javascript; charset=utf-8"); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); out.print(RESTFUL_JS); out.flush(); }
From source file:cn.vlabs.umt.ui.servlet.OauthTokenServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OAuthTokenRequest oauthRequest = null; response.setCharacterEncoding("utf-8"); String redirectURI = null;//from ww w . j a v a2 s. c o m try { response.setContentType("application/json"); if ("validate_access_token".equals(request.getParameter("grant_type"))) { dealValidateAccessToken(request, response); return; } oauthRequest = new OAuthTokenRequest(request); String grantType = oauthRequest.getGrantType(); redirectURI = oauthRequest.getRedirectURI(); if (!validateScope(oauthRequest, response)) { return; } if (!validateRedirectUri(oauthRequest)) { return; } if (!validateSecret(oauthRequest, response)) { return; } if ("authorization_code".equals(grantType)) { String code = oauthRequest.getCode(); if (StringUtils.isEmpty(code)) { dealAppError("invalid_request", "??code?", oauthRequest.getRedirectURI(), response); } else { dealAuthorizationCodeType(request, response, oauthRequest); } } else if ("refresh_token".equals(grantType)) { dealRefreshTokenType(request, response, oauthRequest); } else if ("password".equals(grantType)) { dealPasswordGrantType(oauthRequest, request, response); } else { //???? dealAppError("unsupported_grant_type", grantType + "???", oauthRequest.getRedirectURI(), response); } } catch (OAuthSystemException ex) { dealOAuthSystemError(redirectURI, ex, response); } catch (OAuthProblemException ex) { dealOAuthProblemError(redirectURI, ex, response); } }