List of usage examples for javax.servlet.http HttpServletRequest setCharacterEncoding
public void setCharacterEncoding(String env) throws UnsupportedEncodingException;
From source file:feedme.controller.SearchRestServlet.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request// ww w . jav a 2s .co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); request.setCharacterEncoding("UTF-8"); String city = request.getParameter("where");//get the city int category = Integer.parseInt(request.getParameter("what"));//get the category int page = 1; int recordsPerPage = 6; if (request.getParameter("page") != null) { page = Integer.parseInt(request.getParameter("page")); } List<Restaurant> restaurants = new DbRestaurantsManagement().getNextRecentRestaurantsByCatAndCity(0, recordsPerPage, category, city);//getting a list of restaurants by category and cities int noOfRecords = restaurants.size(); int noOfPages = (int) Math.ceil(noOfRecords * 1.0 / recordsPerPage); if (isAjaxRequest(request)) { try { restaurants = new DbRestaurantsManagement().getNextRecentRestaurantsByCatAndCity( (page - 1) * recordsPerPage, recordsPerPage, category, city);//getting a list of restaurants by category and cities JSONObject restObj = new JSONObject(); JSONArray restArray = new JSONArray(); for (Restaurant rest : restaurants) { restArray.put(new JSONObject().put("resturent", rest.toJson())); } restObj.put("resturent", restArray); restObj.put("noOfPages", noOfPages); restObj.put("currentPage", page); response.setContentType("application/json"); PrintWriter writer = response.getWriter(); writer.print(restObj); response.getWriter().flush(); return; } catch (JSONException e) { e.printStackTrace(); } } request.setAttribute("noOfPages", noOfPages); request.setAttribute("currentPage", page); request.setAttribute("restaurants", restaurants);//return the restaurants to the client RequestDispatcher dispatcher = request.getRequestDispatcher("website/search_rest.jsp"); dispatcher.forward(request, response); }
From source file:com.ikon.servlet.WorkflowRegisterServlet.java
/** * Handle GET and POST//from w ww . jav a 2 s .c o m */ public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("service({}, {}", request, response); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); try { String user = PrincipalUtils.getUser(); if (Config.ADMIN_USER.equals(user)) { String msg = handleRequest(request); log.info("Status: {}", msg); out.print(msg); out.flush(); } else { log.warn("Workflow should be registered by {}", Config.ADMIN_USER); } } catch (FileUploadException e) { log.warn(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "FileUploadException: " + e.getMessage()); } catch (IOException e) { log.warn(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "IOException: " + e.getMessage()); } catch (Exception e) { log.warn(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } finally { IOUtils.closeQuietly(out); } }
From source file:control.HelperServlets.CargarArchivoServlet.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/*from ww w . j a v a2 s .c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); //Obtenemos la opcion que esta opcion = Integer.parseInt(request.getParameter("opcion")); codigo = Integer.parseInt(request.getParameter("codigo")); //Subimos el archivo al servidor //Para poder ser guardado en la bd. subirArchivo(request); //Creamos una referencia al archivo archivo = new File(ruta); try { //Guardamos el archivo en la BD. guardarArchivo(); //Borramos el archivo del servidor archivo.delete(); } catch (Exception ex) { //Logger.getLogger(CargarArchivoServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.gocom.components.coframe.auth.intercepter.FunctionWebInterceptor.java
public void doIntercept(HttpServletRequest request, HttpServletResponse response, IWebInterceptorChain chain) throws IOException, ServletException { request.setCharacterEncoding(MultipartResolver.getEncoding()); if ("true".equals(request.getAttribute(UserLoginWebInterceptor.IS_FILTER_FUNCTION_KEY))) { chain.doIntercept(request, response); return;//www .ja va 2 s .c om } IMUODataContext muo = MUODataContextHelper.create(request.getSession()); DataContextManager.current().setMUODataContext(muo); String resId = request.getParameter(IAuthConstants.FUNCTION_PARAN_RESOURCE_ID); String resType = request.getParameter(IAuthConstants.FUNCTION_PARAM_REAOURCE_TYPE); if (StringUtil.isNotEmpty(resType) && !IAuthConstants.FUNCTION_TO_RESOURCE_TYPE.equals(resType)) { chain.doIntercept(request, response); return; } IManagedResource managedResource = null; if (StringUtils.isEmpty(resId) || StringUtils.isEmpty(resType)) { managedResource = getManagedResource(request); } else { managedResource = ResourceRuntimeManager.getInstance().getManagedResource(resId, resType); } if (hasPermission(managedResource, request)) { chain.doIntercept(request, response); } else { request.getRequestDispatcher("/coframe/auth/noAuth.jsp").forward(request, response); } }
From source file:de.betterform.agent.web.servlet.ViewServlet.java
/** * This method is only called when non-scripted mode is used to update the UI. This basically exists to support * the PFG (POST/FORWARD/GET) pattern that allows to use the browser back button without POSTDATA warning from the browser * and to re-initialize the preceding form (if any). * <p/>//from ww w.j a v a2 s.c o m * To make sure that an update is requested from the XFormsSession and not by the user clicking the reload button the * XFormsSession holds a property XFormsSession.UPDATE_REQUEST when coming from XFormsSession. If this property exists, * the UI is refreshed otherwise the form is re-inited with a GET. * * @param request servlet request * @param response servlet response * @throws javax.servlet.ServletException * @throws java.io.IOException */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { XFormsProcessor webAdapter = null; HttpSession session = request.getSession(true); request.setCharacterEncoding("UTF-8"); WebUtil.nonCachingResponse(response); String referer = request.getParameter("referer"); WebProcessor webProcessor = WebUtil.getWebProcessor(request, response, session); try { if (webProcessor == null || webProcessor.getContextParam("update") == null) { LOGGER.info("session does not exist: creating new one"); //todo: this has to be moved out in config or determined from request somehow - this won't work with the XFormsFilter // response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/XFormsServlet?" + referer)); response.sendRedirect(response.encodeRedirectURL(referer)); } else { //todo: check here if we got called by the WebProcessor or directly e.g. through a reload //todo: if not send back to XFormsServlet webProcessor.removeContextParam("update"); response.setContentType(WebUtil.HTML_CONTENT_TYPE); UIGenerator uiGenerator = (UIGenerator) webProcessor.getContextParam(WebProcessor.UIGENERATOR); uiGenerator.setInput(webAdapter.getXForms()); uiGenerator.setOutput(response.getOutputStream()); uiGenerator.generate(); response.getOutputStream().close(); } } catch (Exception e) { webProcessor.close(e); } }
From source file:hd.controller.AddImageToIdeaBookServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww .j a va 2 s . co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (!isMultipart) { //to do } else { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = null; try { items = upload.parseRequest(request); } catch (FileUploadException e) { e.printStackTrace(); } Iterator iter = items.iterator(); Hashtable params = new Hashtable(); String fileName = null; while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { params.put(item.getFieldName(), item.getString("UTF-8")); } else if (!item.isFormField()) { try { long time = System.currentTimeMillis(); String itemName = item.getName(); fileName = time + itemName.substring(itemName.lastIndexOf("\\") + 1); String RealPath = getServletContext().getRealPath("/") + "images\\" + fileName; File savedFile = new File(RealPath); item.write(savedFile); String localPath = "D:\\Project\\TestHouseDecor-Merge\\web\\images\\" + fileName; // savedFile = new File(localPath); // item.write(savedFile); } catch (Exception e) { e.printStackTrace(); } } } String ideaBookIdTemp = (String) params.get("txtIdeabookId"); int ideaBookId = Integer.parseInt(ideaBookIdTemp); IdeaBookDAO ideabookDao = new IdeaBookDAO(); String tilte = (String) params.get("newGalleryName"); String description = (String) params.get("GalleryDescription"); String url = "images/" + fileName; IdeaBookPhotoDAO photoDAO = new IdeaBookPhotoDAO(); IdeaBookPhoto ideaBookPhoto = photoDAO.insertIdeaBookPhoto(tilte, description, url, ideaBookId); HDSystem system = new HDSystem(); system.setNotificationIdeaBook(request); response.sendRedirect("MyIdeaBookDetailServlet?txtIdeabookId=" + ideaBookId); } } catch (Exception e) { e.printStackTrace(); } finally { out.close(); } }
From source file:com.sbu.controller.ServletPersonalStartupController.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response);/*w w w. ja va 2s . c om*/ response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); String id = request.getParameter("id"); Startup SearchQueries = null; List<Startup> sta = startupService.getAllStartups(); List<Member1> mem = memberService.getAllMembers(); for (int i = 0; i < sta.size(); i++) { if (sta.get(i).getIdStartup() == Integer.parseInt(id)) { SearchQueries = sta.get(i); break; } } for (int i = 0; i < mem.size(); i++) { if (mem.get(i).getStartupidStartup().equals(SearchQueries)) { members.add(mem.get(i)); } } request.setAttribute("SearchQueries", SearchQueries); request.setAttribute("members", members); request.getRequestDispatcher("Personal_Startup.jsp").forward(request, response); }
From source file:com.ikon.servlet.admin.CheckTextExtractionServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doGet({}, {})", request, response); request.setCharacterEncoding("UTF-8"); updateSessionManager(request);//from w ww .java2 s . com ServletContext sc = getServletContext(); sc.setAttribute("repoPath", "/" + Repository.ROOT); sc.setAttribute("docUuid", null); sc.setAttribute("text", null); sc.setAttribute("time", null); sc.setAttribute("mimeType", null); sc.setAttribute("extractor", null); sc.getRequestDispatcher("/admin/check_text_extraction.jsp").forward(request, response); }
From source file:org.nuxeo.wss.servlet.WSSFilter.java
protected void handleWSSCall(HttpServletRequest httpRequest, HttpServletResponse httpResponse, FilterBindingConfig config) throws Exception { httpRequest.setCharacterEncoding("UTF-8"); httpResponse.setCharacterEncoding("UTF-8"); WSSRequest request = new WSSRequest(httpRequest, config.getSiteName()); WSSResponse response = null;/*from ww w. j a va2 s .com*/ WSSBackend backend = Backend.get(request); backend.begin(); log.debug("Handling WSS call : " + httpRequest.getRequestURL().toString()); try { if (FilterBindingConfig.FP_REQUEST_TYPE.equals(config.getRequestType())) { FPRPCRequest fpRequest = new FPRPCRequest(httpRequest, config.getSiteName()); request = fpRequest; response = new FPRPCResponse(httpResponse); FPRPCRouter.handleFPRCPRequest(fpRequest, (FPRPCResponse) response, config); } else if (FilterBindingConfig.GET_REQUEST_TYPE.equals(config.getRequestType())) { response = new WSSResponse(httpResponse); simpleGetHandler.handleRequest(request, response); } else if (FilterBindingConfig.RESOURCES_REQUEST_TYPE.equals(config.getRequestType())) { resourcesHandler.handleResource(httpRequest, httpResponse); return; } else if (FilterBindingConfig.FAKEWS_REQUEST_TYPE.equals(config.getRequestType())) { FakeWSRequest wsRequest = new FakeWSRequest(httpRequest, config.getSiteName()); request = wsRequest; response = new WSSResponse(httpResponse); FakeWSRouter.handleFakeWSRequest(wsRequest, response, config); } if (response == null) { log.error("no response was created by WSS call handling"); throw new ServletException("WSSResponse is not set"); } else { response.processIfNeeded(); } backend.saveChanges(); } catch (Throwable t) { backend.discardChanges(); log.error("Error during WSS call processing", t); throw new WSSException("Error while processing WSS request", t); } }
From source file:ua.aits.crc.controller.SystemController.java
@RequestMapping(value = { "/system/do/logout", "/system/do/logout/" }) public ModelAndView logout(HttpServletRequest request, HttpServletResponse response) throws Exception { request.setCharacterEncoding("UTF-8"); HttpSession session = request.getSession(false); if (session != null) { session.invalidate();/*w w w . j a v a 2s . com*/ } return new ModelAndView("redirect:" + "/system/login"); }