List of usage examples for javax.servlet.http HttpServletRequest setCharacterEncoding
public void setCharacterEncoding(String env) throws UnsupportedEncodingException;
From source file:ilearn.orb.controller.AnalysisController.java
@RequestMapping(value = "/analysis") public ModelAndView textAnalysis(Locale locale, ModelMap modelMap, HttpServletRequest request, HttpSession session) {/*from ww w. j a v a 2s . com*/ try { request.setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } ModelAndView model = new ModelAndView(); model.setViewName("analysis"); try { Gson gson = new GsonBuilder().registerTypeAdapter(java.util.Date.class, new UtilDateDeserializer()) .setDateFormat(DateFormat.LONG).create(); User[] students = null; try { String json = UserServices.getProfiles(Integer.parseInt(session.getAttribute("id").toString()), session.getAttribute("auth").toString()); students = gson.fromJson(json, User[].class); } catch (NullPointerException e) { } if (students == null || students.length == 0) { students = HardcodedUsers.defaultStudents(); } modelMap.put("students", students); String text = request.getParameter("inputText"); String profileId = request.getParameter("selectedId"); if (text != null) { text = new String(text.getBytes("8859_1"), "UTF-8"); } else text = ""; modelMap.put("profileId", profileId); modelMap.put("text", text); String json; if (Integer.parseInt(profileId) > 0) json = TextServices.getAnalysisJson(Integer.parseInt(profileId), session.getAttribute("auth").toString(), text); else json = TextServices .getAnalysisJson(HardcodedUsers.defaultProfileLanguage(Integer.parseInt(profileId)), text); AnalysisResults analysisResults = null; analysisResults = (new Gson()).fromJson(json, AnalysisResults.class); modelMap.put("analysisResults", analysisResults); UserProfile pr = retrieveProfile(session, Integer.parseInt(profileId)); modelMap.put("selectedProfile", pr); int maxWordsMatched = 0; for (int i = 0; i < pr.getUserProblems().getNumerOfRows(); i++) { for (int j = 0; j < pr.getUserProblems().getRowLength(i); j++) { if (analysisResults.getUserCounters().getValue(i, j) > maxWordsMatched) maxWordsMatched = analysisResults.getUserCounters().getValue(i, j); } } modelMap.put("maxWordsMatched", maxWordsMatched); } catch (NumberFormatException e) { //e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return model; }
From source file:com.jyhon.servlet.user.SignInServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //?//from w w w . j a v a 2 s .c om request.setCharacterEncoding("UTF-8"); //?IOC? UserEntityService userEntityService = new UserEntityServiceImpl(); //? String pathTemp = InitFileFolder(); List<FileItem> items = getFileItems(request, pathTemp); UserEntity userEntity = getUserEntity(items); //??? VerifyUtil verifyUtil = new VerifyUtil(); if (verifySignInData(request, response, userEntity, verifyUtil)) return; //?? Integer dbResult = userEntityService.addEntity(userEntity); //?? if (dbResult <= 0) { request.setAttribute("ErrorMessage", "DataBase Insert fail!"); request.getRequestDispatcher("register.jsp").forward(request, response); return; } //? request.setAttribute("ReminderMessage", "Register Success please login"); request.getRequestDispatcher("login.jsp").forward(request, response); }
From source file:org.finra.herd.ui.RequestLoggingFilterTest.java
/** * Test to get the coverage for unused implemented methods of RequestLoggingFilterWrapper. *//*from ww w .jav a 2 s . com*/ @Test public void testRequestLoggingFilterWrapper() throws Exception { HttpServletRequest servletRequest = createServletRequest(); servletRequest.setCharacterEncoding(WebUtils.DEFAULT_CHARACTER_ENCODING); RequestLoggingFilter requestLoggingFilter = new RequestLoggingFilter(); RequestLoggingFilter.RequestLoggingFilterWrapper wrapper = requestLoggingFilter.new RequestLoggingFilterWrapper( servletRequest); wrapper.logRequest(servletRequest); wrapper.getContentLength(); wrapper.getCharacterEncoding(); wrapper.getReader(); wrapper.getReader(); }
From source file:org.josso.gatein.agent.GateInSSOAgentFilter.java
private boolean isLogoutInProgress(HttpServletRequest request) throws UnsupportedEncodingException { // set character encoding before retrieving request parameters if (fileEncoding != null) { request.setCharacterEncoding(fileEncoding); }/* ww w. java2s . c o m*/ String action = request.getParameter("portal:action"); if (action != null && action.equals("Logout")) { return true; } return false; }
From source file:feedme.controller.AddOrDeleteCategoryServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response);//from www . j a v a2s .com request.setCharacterEncoding("UTF-8"); response.setStatus(HttpServletResponse.SC_OK); String CategoryName = request.getParameter("categoryName").trim(); DbRestaurantsManagement ob = new DbRestaurantsManagement(); boolean flag = false; HashMap<String, Integer> cat = new DbHPOnLoad().getCategories(); for (String se : cat.keySet()) { if (se.contains(CategoryName)) flag = true; } int result = 0; if (!flag) result = ob.addNewCategory(CategoryName); PrintWriter out = response.getWriter(); if (result == 1) { if (isAjax(request) == true) { // Stay in the same page, and sand json message try { cat = new DbHPOnLoad().getCategories(); JSONObject catObj = new JSONObject(); JSONArray catArray = new JSONArray(); for (Entry<String, Integer> entry : cat.entrySet()) { catArray.put( new JSONObject().put("cat_id", entry.getValue()).put("cat_name", entry.getKey())); } catObj.put("categories", catArray); catObj.put("status", true); response.setContentType("application/json"); PrintWriter writer = response.getWriter(); writer.print(catObj); response.getWriter().flush(); } catch (JSONException e) { e.printStackTrace(); } } else { // redirect to othe page } } }
From source file:com.slience.controller.AuthController.java
@RequestMapping("role/show/{pageIndex}/{limit}") @ResponseBody/*from ww w . j a v a 2s. c om*/ public List<?> handRoleShowRequest(HttpServletRequest request, HttpServletResponse response, @PathVariable("pageIndex") int pageIndex, @PathVariable("limit") int limit) throws Exception { request.setCharacterEncoding("UTF-8"); response.setContentType("application/json;charset=UTF-8"); return null; }
From source file:com.slience.controller.AuthController.java
@RequestMapping("user/show/{pageIndex}/{limit}") @ResponseBody//from w w w. j a va2 s . c o m public List<?> handUserShowRequest(HttpServletRequest request, HttpServletResponse response, @PathVariable("pageIndex") int pageIndex, @PathVariable("limit") int limit) throws Exception { request.setCharacterEncoding("UTF-8"); response.setContentType("application/json;charset=UTF-8"); return null; }
From source file:com.slience.controller.AuthController.java
@RequestMapping("user/search/{pageIndex}/{limit}") @ResponseBody/*from ww w . j av a2 s .c o m*/ public List<?> handUserSearchRequest(HttpServletRequest request, HttpServletResponse response, @PathVariable("pageIndex") int pageIndex, @PathVariable("limit") int limit) throws Exception { request.setCharacterEncoding("UTF-8"); response.setContentType("application/json;charset=UTF-8"); return null; }
From source file:org.finra.dm.ui.RequestLoggingFilterTest.java
/** * Test to get the coverage for unused implemented methods of RequestLoggingFilterWrapper. *//*from www.j a v a 2 s . c o m*/ @Test public void testRequestLoggingFilterWrapper() throws Exception { HttpServletRequest servletRequest = createServletRequest(); servletRequest.setCharacterEncoding(WebUtils.DEFAULT_CHARACTER_ENCODING); RequestLoggingFilter requestLoggingFilter = new RequestLoggingFilter(); RequestLoggingFilter.RequestLoggingFilterWrapper wrapper = requestLoggingFilter.new RequestLoggingFilterWrapper( servletRequest); wrapper.getContentLength(); wrapper.getCharacterEncoding(); wrapper.getReader(); wrapper.getReader(); }
From source file:de.betterform.agent.web.servlet.XFormsRequestURIServlet.java
/** * This servlet uses the requestURI to locate and parse a XForms document for processing. The actual processing * is done by XFormsFilter. The parsed DOM of the document is passed as a request param to the filter. * * @param request servlet request// w ww . j a va 2 s .com * @param response servlet response * @throws javax.servlet.ServletException * @throws java.io.IOException */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOGGER.debug("hit XFormsRequestURIServlet"); request.setCharacterEncoding("UTF-8"); WebUtil.nonCachingResponse(response); Document doc; //locate it String formRequestURI = request.getRequestURI().substring(request.getContextPath().length() + 1); String realPath = null; try { realPath = WebFactory.getRealPath(formRequestURI, getServletContext()); } catch (XFormsConfigException e) { throw new ServletException(e); } File xfDoc = new File(realPath); if (request.getHeader("betterform-internal") != null) { BufferedInputStream in = new BufferedInputStream(new FileInputStream(xfDoc)); BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); int read; while ((read = in.read()) > -1) { out.write(read); } out.flush(); } else { try { //parse it doc = DOMUtil.parseXmlFile(xfDoc, true, false); } catch (ParserConfigurationException e) { throw new ServletException(e); } catch (SAXException e) { throw new ServletException(e); } request.setAttribute(WebFactory.XFORMS_NODE, doc); //do the Filter twist response.getOutputStream().close(); } }