List of usage examples for javax.servlet.http HttpServletRequest setCharacterEncoding
public void setCharacterEncoding(String env) throws UnsupportedEncodingException;
From source file:com.slience.controller.AuthController.java
@RequestMapping("user/delete/{id}") @ResponseBody// w w w . j a v a 2s. co m public Map<String, ?> handUserDeleteRequest(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") String id) throws Exception { request.setCharacterEncoding("UTF-8"); response.setContentType("application/json;charset=UTF-8"); return null; }
From source file:com.enonic.cms.web.filter.CharacterEncodingFilter.java
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (request.getCharacterEncoding() == null) { request.setCharacterEncoding(encoding); }/*from w w w. j a v a 2 s. c o m*/ final String forcedCharset = request.getParameter("_charset"); if (!StringUtils.isBlank(forcedCharset)) { response.setCharacterEncoding(forcedCharset); } else { response.setCharacterEncoding(encoding); } filterChain.doFilter(request, response); }
From source file:com.ikon.servlet.DownloadServlet.java
/** * //from w w w . ja v a2 s .co m */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { request.setCharacterEncoding("UTF-8"); String userId = request.getRemoteUser(); String path = WebUtils.getString(request, "path"); String uuid = WebUtils.getString(request, "uuid"); boolean inline = WebUtils.getBoolean(request, "inline"); InputStream is = null; try { // Now an document can be located by UUID if (uuid != null && !uuid.equals("")) { path = OKMRepository.getInstance().getNodePath(null, uuid); } if (path != null) { Document doc = OKMDocument.getInstance().getProperties(null, path); String fileName = PathUtils.getName(doc.getPath()); log.info("Download {} by {} ({})", new Object[] { path, userId, (inline ? "inline" : "attachment") }); is = OKMDocument.getInstance().getContent(null, path, false); WebUtils.sendFile(request, response, fileName, doc.getMimeType(), inline, is); } else { response.setContentType("text/plain; charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("Missing document reference"); out.close(); } } catch (PathNotFoundException e) { log.warn(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "PathNotFoundException: " + e.getMessage()); } catch (RepositoryException e) { log.warn(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "RepositoryException: " + e.getMessage()); } catch (Exception e) { log.warn(e.getMessage(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } finally { IOUtils.closeQuietly(is); } }
From source file:controller.updateProduct.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// ww w .ja va 2 s. c om * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); String cmd = request.getParameter("sub"); switch (cmd) { case "update": updateProduct(request, response); break; } }
From source file:com.sishistorico.sv.SvHistorico.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . j a v a2s . c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF8"); response.setContentType("text/html;charset=UTF-8"); List<FileItem> items = null; try { items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); DateFormat formatter; Date data_entrada; Date data_agendada = null; formatter = new SimpleDateFormat("dd/MM/yyyy"); data_entrada = (Date) formatter.parse(items.get(2).getString()); if (!items.get(4).getString().equals("")) { data_agendada = (Date) formatter.parse(items.get(4).getString()); } // fim do tratamento Historico hi = new Historico(); hi.setId_eleitor(Integer.parseInt(items.get(0).getString().trim())); hi.setData_entrada(data_entrada); hi.setTipo(Integer.parseInt(items.get(3).getString().trim())); hi.setData_agendada(data_agendada); hi.setSituacao(Integer.parseInt(items.get(7).getString().trim())); hi.setSolicitacao(items.get(5).getString("UTF-8").trim()); DaoHistorico daoHistorico = new DaoHistorico(); daoHistorico.historico_Salvar(hi); response.sendRedirect("cadastro_historico.jsp?id=" + hi.getId_eleitor() + "&msgok=Salvo com sucesso!"); } catch (FileUploadException ex) { Logger.getLogger(SvHistorico.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(SvHistorico.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.sishistorico.sv.SvHistoricoEditar.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*ww w . j av a2 s . c o 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 */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF8"); response.setContentType("text/html;charset=UTF-8"); List<FileItem> items = null; try { items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); DateFormat formatter; Date data_entrada; Date data_agendada = null; formatter = new SimpleDateFormat("dd/MM/yyyy"); data_entrada = (Date) formatter.parse(items.get(2).getString()); if (!items.get(4).getString().equals("")) { data_agendada = (Date) formatter.parse(items.get(4).getString()); } // fim do tratamento Historico hi = new Historico(); hi.setId_eleitor(Integer.parseInt(items.get(0).getString().trim())); hi.setData_entrada(data_entrada); hi.setTipo(Integer.parseInt(items.get(3).getString().trim())); hi.setData_agendada(data_agendada); hi.setSituacao(Integer.parseInt(items.get(7).getString().trim())); hi.setSolicitacao(items.get(5).getString("UTF-8").trim()); hi.setId(Integer.parseInt(items.get(8).getString("UTF-8").trim())); DaoHistorico daoHistorico = new DaoHistorico(); daoHistorico.historico_editar(hi); response.sendRedirect("editar_historico.jsp?id=" + hi.getId() + "&msgok=Editado com sucesso!"); } catch (FileUploadException ex) { Logger.getLogger(SvHistoricoEditar.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(SvHistoricoEditar.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:cdc.util.Upload.java
public boolean anexos(HttpServletRequest request) throws Exception { request.setCharacterEncoding("ISO-8859-1"); if (ServletFileUpload.isMultipartContent(request)) { int cont = 0; ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory()); List fileItemsList = null; try {/*from w ww. ja va 2 s .c o m*/ fileItemsList = servletFileUpload.parseRequest(request); } catch (FileUploadException e) { e.printStackTrace(); } String optionalFileName = ""; FileItem fileItem = null; Iterator it = fileItemsList.iterator(); do { //cont++; FileItem fileItemTemp = (FileItem) it.next(); if (fileItemTemp.isFormField()) { if (fileItemTemp.getFieldName().equals("file")) { optionalFileName = fileItemTemp.getString(); } parametros.put(fileItemTemp.getFieldName(), fileItemTemp.getString()); } else { fileItem = fileItemTemp; } if (cont != (fileItemsList.size())) { if (fileItem != null) { String fileName = fileItem.getName(); if (fileItem.getSize() > 0) { if (optionalFileName.trim().equals("")) { fileName = FilenameUtils.getName(fileName); } else { fileName = optionalFileName; } String dirName = request.getServletContext().getRealPath(pasta); File saveTo = new File(dirName + "/" + fileName); //verificando se a pasta existe. Caso contrrio, criar ela File pasta = new File(dirName); if (!pasta.exists()) pasta.mkdirs();//criando a pasta parametros.put("foto", fileName); try { fileItem.write(saveTo);//Escrevendo o arquivo temporrio no diretrio correto } catch (Exception e) { } } } } cont++; } while (it.hasNext()); return true; } else { return false; } }
From source file:de.betterform.agent.web.servlet.XFormsPostServlet.java
/** * read from the inputStream and parse that as DOM. The result is passed into a request attribute for * processing by the XFormsFilter./* www . j ava 2 s.c o m*/ * * @param request servlet request * @param response servlet response * @throws javax.servlet.ServletException * @throws java.io.IOException */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOGGER.debug("hit XFormsPostServlet"); request.setCharacterEncoding("UTF-8"); WebUtil.nonCachingResponse(response); Document doc; try { //parse it doc = DOMUtil.parseInputStream(request.getInputStream(), true, false); } catch (ParserConfigurationException e) { throw new ServletException(e); } catch (SAXException e) { throw new ServletException(e); } //do the Filter twist request.setAttribute(WebFactory.XFORMS_NODE, doc); request.setAttribute(XFormsPostServlet.INIT_BY_POST, doc); response.getOutputStream().close(); }
From source file:de.mpg.escidoc.services.aa.web.AaStart.java
/** * This servlet is expecting 2 parameters: * //from w ww .ja va 2s . c om * - tan: A random string generated by the client system to check whether the result is valid or not. * - target: The URL the user should be redirected to after authentication. * */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding(DEFAULT_ENCODING); response.setCharacterEncoding(DEFAULT_ENCODING); String from = request.getParameter("from"); String tan = request.getParameter("tan"); // TODO: Make this generic String handle = request.getParameter("eSciDocUserHandle"); Matcher matcher = authPattern.matcher(from); from = matcher.replaceAll(""); String target = request.getParameter("target"); if (target == null) { target = Config.getProperty("escidoc.aa.default.target"); } String separator = "?"; if (target.contains("?")) { separator = "&"; } target += separator + "target=" + URLEncoder.encode(from, "ISO-8859-1") + "&tan=" + URLEncoder.encode(tan, "ISO-8859-1"); if (handle != null) { target += "&eSciDocUserHandle=" + URLEncoder.encode(handle, "ISO-8859-1"); } response.sendRedirect(target); }
From source file:org.seasar.mayaa.impl.MayaaServlet.java
protected void setupCharacterEncoding(HttpServletRequest request, String encoding) { if (request.getCharacterEncoding() == null) { try {//w ww . j a v a 2 s. c o m request.setCharacterEncoding(encoding); } catch (UnsupportedEncodingException e) { String message = StringUtil.getMessage(MayaaServlet.class, 0, encoding); LOG.warn(message, e); } } }