List of usage examples for javax.servlet.http HttpServletRequest setCharacterEncoding
public void setCharacterEncoding(String env) throws UnsupportedEncodingException;
From source file:org.jeedevframework.jpush.server.console.controller.UserController.java
public ModelAndView getUser(HttpServletRequest request, HttpServletResponse response) throws Exception { //response.setHeader("Content-type","text/html;charset=UTF-8");//????????UTF-8 OutputStream stream = response.getOutputStream(); String result = "failed"; request.setCharacterEncoding("UTF-8"); try {/*from w ww .j a va 2 s.co m*/ String data = request.getParameter("userName"); if (data == null) { } else { User user = userService.getUserByUsername(data); if (user == null) { } else { result = "success"; } } } catch (Exception e) { } stream.write(result.getBytes("utf-8")); // ModelAndView mav = new ModelAndView(); // mav.addObject("userList", userList); // mav.setViewName("index"); return null; }
From source file:ua.aits.sdolyna.controller.SystemController.java
@RequestMapping(value = { "/Sdolyna/system/delete/{id}", "/system/delete/{id}", "/Sdolyna/system/delete/{id}/", "/system/delete/{id}/" }) public ModelAndView deleteArticle(@PathVariable("id") String id, HttpServletRequest request, HttpServletResponse response) throws Exception { request.setCharacterEncoding("UTF-8"); ArticleModel temp = Articles.getArticleByID(id); Articles.deleteArticle(id);// w w w . j av a 2 s . c o m return new ModelAndView("redirect:" + "/system/index/" + temp.article_category); }
From source file:com.openkm.servlet.admin.CheckTextExtractionServlet.java
@SuppressWarnings("unchecked") public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doPost({}, {})", request, response); request.setCharacterEncoding("UTF-8"); updateSessionManager(request);//w w w . j a va 2 s . c o m InputStream is = null; try { if (ServletFileUpload.isMultipartContent(request)) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request); String docUuid = null; String repoPath = null; String text = null; String error = null; String mimeType = null; String extractor = null; for (Iterator<FileItem> it = items.iterator(); it.hasNext();) { FileItem item = it.next(); if (item.isFormField()) { if (item.getFieldName().equals("docUuid")) { docUuid = item.getString("UTF-8"); } else if (item.getFieldName().equals("repoPath")) { repoPath = item.getString("UTF-8"); } } else { is = item.getInputStream(); String name = FilenameUtils.getName(item.getName()); mimeType = MimeTypeConfig.mimeTypes.getContentType(name.toLowerCase()); if (!name.isEmpty() && item.getSize() > 0) { docUuid = null; repoPath = null; } else if (docUuid.isEmpty() && repoPath.isEmpty()) { mimeType = null; } } } if (docUuid != null && !docUuid.isEmpty()) { repoPath = OKMRepository.getInstance().getNodePath(null, docUuid); } if (repoPath != null && !repoPath.isEmpty()) { String name = PathUtils.getName(repoPath); mimeType = MimeTypeConfig.mimeTypes.getContentType(name.toLowerCase()); is = OKMDocument.getInstance().getContent(null, repoPath, false); } long begin = System.currentTimeMillis(); if (is != null) { if (!MimeTypeConfig.MIME_UNDEFINED.equals(mimeType)) { TextExtractor extClass = RegisteredExtractors.getTextExtractor(mimeType); if (extClass != null) { try { extractor = extClass.getClass().getCanonicalName(); text = RegisteredExtractors.getText(mimeType, null, is); } catch (Exception e) { error = e.getMessage(); } } else { extractor = "Undefined text extractor"; } } } ServletContext sc = getServletContext(); sc.setAttribute("docUuid", docUuid); sc.setAttribute("repoPath", repoPath); sc.setAttribute("text", text); sc.setAttribute("time", System.currentTimeMillis() - begin); sc.setAttribute("mimeType", mimeType); sc.setAttribute("error", error); sc.setAttribute("extractor", extractor); sc.getRequestDispatcher("/admin/check_text_extraction.jsp").forward(request, response); } } catch (DatabaseException e) { sendErrorRedirect(request, response, e); } catch (FileUploadException e) { sendErrorRedirect(request, response, e); } catch (PathNotFoundException e) { sendErrorRedirect(request, response, e); } catch (AccessDeniedException e) { sendErrorRedirect(request, response, e); } catch (RepositoryException e) { sendErrorRedirect(request, response, e); } finally { IOUtils.closeQuietly(is); } }
From source file:net.xy.jcms.shared.adapter.HttpRequestDataAccessContext.java
/** * default constructor/*w w w .ja va2 s. c om*/ * * @param request * @throws MalformedURLException * @throws URISyntaxException */ public HttpRequestDataAccessContext(final HttpServletRequest request) throws MalformedURLException, URISyntaxException { // gets cappsubrand default locale and various other jj related // informations mendatory to retrieve jj configuration try { request.setCharacterEncoding("UTF-8"); } catch (final UnsupportedEncodingException e) { } contextPath = request.getContextPath() + "/"; requestPath = request.getPathInfo().length() > 0 && request.getPathInfo().charAt(0) == '/' ? request.getPathInfo().substring(1) : request.getPathInfo(); rootUrl = new URI(request.getProtocol().split("/", 2)[0], null, request.getLocalName(), request.getLocalPort(), "/", null, null); // properties if (request.getParameter("flushConfig") != null) { properties.put("flushConfig", true); } }
From source file:com.openkm.servlet.admin.PropertyGroupsServlet.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doGet({}, {})", request, response); request.setCharacterEncoding("UTF-8"); String action = WebUtils.getString(request, "action"); Session session = null;//from w ww . ja v a 2 s. co m updateSessionManager(request); try { // session = JCRUtils.getSession(); if (action.equals("register")) { register(session, request, response); } else if (action.equals("edit")) { edit(request, response); } if (action.equals("") || action.equals("register")) { list(request, response); } } catch (LoginException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (RepositoryException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (DatabaseException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (javax.jcr.RepositoryException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (ParseException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (org.apache.jackrabbit.core.nodetype.compact.ParseException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (InvalidNodeTypeDefException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } finally { // JCRUtils.logout(session); } }
From source file:jp.mathes.databaseWiki.web.DbwServlet.java
private void handleHttp(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); resp.setCharacterEncoding("UTF-8"); String user = null;/* w w w. j av a 2 s. c o m*/ String password = null; if (req.getHeader("Authorization") != null) { String[] split = req.getHeader("Authorization").split(" "); String userpw = ""; if (split.length > 1) { userpw = new String(Base64.decodeBase64(split[1])); } user = StringUtils.substringBefore(userpw, ":"); password = StringUtils.substringAfter(userpw, ":"); resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("application/xhtml+xml; charset=UTF-8"); try { this.handleAction(req, resp, user, password); } catch (InstantiationException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not instantiate database backend: " + e.getMessage()); } catch (IllegalAccessException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Illegal Access: " + e.getMessage()); } catch (ClassNotFoundException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not find database backend: " + e.getMessage()); } catch (TemplateException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Template error: " + e.getMessage()); } catch (BackendException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Database error: " + e.getMessage()); } catch (PluginException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Rendering error: " + e.getMessage()); } } else { resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); resp.setHeader("WWW-Authenticate", "Basic realm=\"databaseWiki\""); } }
From source file:ilearn.orb.controller.AnnotationController.java
@RequestMapping(value = "/annotation/{userid}", method = RequestMethod.GET) public ModelAndView textUserAnnotation(Locale locale, ModelMap modelMap, HttpServletRequest request, HttpSession session, @PathVariable("userid") Integer userid) { try {//from ww w . j a v a 2 s . co m request.setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } txModule = new TextAnnotationModule(); ModelAndView model = new ModelAndView(); model.setViewName("annotation"); try { User[] students = null; UserProfile p = null; User selectedStudent = null; if (userid < 0) { students = HardcodedUsers.defaultStudents(); selectedStudent = selectedStudent(students, userid.intValue()); // p = HardcodedUsers.defaultProfile(selectedStudent.getId()); String json = UserServices .getDefaultProfile(HardcodedUsers.defaultProfileLanguage(selectedStudent.getId())); if (json != null) p = new Gson().fromJson(json, UserProfile.class); } else { Gson gson = new GsonBuilder().registerTypeAdapter(java.util.Date.class, new UtilDateDeserializer()) .setDateFormat(DateFormat.LONG).create(); String json = UserServices.getProfiles(Integer.parseInt(session.getAttribute("id").toString()), session.getAttribute("auth").toString()); students = gson.fromJson(json, User[].class); selectedStudent = selectedStudent(students, userid.intValue()); json = UserServices.getJsonProfile(userid, session.getAttribute("auth").toString()); if (json != null) p = new Gson().fromJson(json, UserProfile.class); } modelMap.put("profileId", userid); modelMap.put("selectedStudent", selectedStudent); modelMap.put("students", students); modelMap.put("selectedProfile", p); ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader .getResource("data/" + (selectedStudent.getLanguage().toLowerCase()) + ".json").getFile()); String js = LocalStorageTextFileHandler.loadFileAsString(file); Groups grps = new Gson().fromJson(js, Groups.class); modelMap.put("presents", grps); } catch (NumberFormatException e) { //e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return model; }
From source file:com.ikon.servlet.admin.CssServlet.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doGet({}, {})", request, response); request.setCharacterEncoding("UTF-8"); String action = WebUtils.getString(request, "action"); String userId = request.getRemoteUser(); updateSessionManager(request);/* w w w . jav a 2 s. c o m*/ try { if (action.equals("create")) { create(userId, request, response); } else if (action.equals("edit")) { edit(userId, request, response); } else if (action.equals("delete")) { delete(userId, request, response); } else if (action.equals("download")) { download(userId, request, response); } if (action.equals("") || WebUtils.getBoolean(request, "persist")) { list(userId, request, response); } } catch (DatabaseException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } }
From source file:jease.cms.web.servlet.JeaseController.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); String uri = request.getRequestURI(); // Strip jsessionid from URI. int jsessionidIndex = uri.indexOf(";jsessionid="); if (jsessionidIndex != -1) { uri = uri.substring(0, jsessionidIndex); }//from w ww. ja v a2 s.co m // Process internal context prefix int tilde = uri.indexOf("~"); if (tilde != -1) { String path = uri.substring(tilde + 1); response.sendRedirect(response .encodeRedirectURL(buildURI(request.getContextPath() + path, request.getQueryString()))); return; } // Try to resolve node from URI (without context path). String nodePath = uri.substring(request.getContextPath().length()); Node node = Nodes.getByPath(nodePath); // Process redirect rules if (node == null && !servlets.matcher(nodePath).matches()) { String sourceURI = buildURI(nodePath, request.getQueryString()); String targetURI = rewriteURI(sourceURI); if (!targetURI.equals(sourceURI)) { if (targetURI.contains("://")) { response.sendRedirect(response.encodeRedirectURL(targetURI)); } else { response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + targetURI)); } return; } } // Save "virtual" root node. Per default it is the absolute root of the // instance. // If a node with the server name exists, this node is used as virtual // root. if (request.getAttribute("Root") == null) { String server = Servlets.getServerName(request).replaceFirst("www.", ""); Node root = Nodes.getRoot() != null ? Nodes.getRoot().getChild(server) : null; if (root == null) { root = Nodes.getRoot(); } if (node != null) { if (node.getParent() == root && locales.contains(node.getId())) { root = node; } else { for (Node parent : node.getParents()) { if (parent.getParent() == root && locales.contains(parent.getId())) { root = parent; break; } } } } request.setAttribute("Root", root); if (node != null && root.getParent() == node) { response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + root.getPath())); return; } } // If no node is found, process filter chain. if (node == null) { chain.doFilter(request, response); return; } // Redirect if trailing slash is missing for containers. if (node.isContainer() && !uri.endsWith("/")) { response.sendRedirect(response.encodeRedirectURL(buildURI(uri + "/", request.getQueryString()))); } else { // Set node into request scope and forward to dispatcher request.setAttribute(Node.class.getSimpleName(), node); request.setAttribute(Names.JEASE_SITE_DISPATCHER, dispatcher); Function<String, String> rewriter = StringUtils.isNotBlank( Registry.getParameter(Names.JEASE_SITE_REWRITER)) ? Database.query(rewriterSupplier) : null; request.getRequestDispatcher(dispatcher).forward(request, rewriter != null ? new ResponseRewriter(response, rewriter) : response); } }
From source file:ngse.org.FileUploadServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Map<String, String> fields = new HashMap<String, String>(); List<String> fileNames = new ArrayList<String>(); request.setCharacterEncoding("UTF-8"); String result = FileUpload(fields, fileNames, request, response); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=utf-8"); PrintWriter out = response.getWriter(); if (result == null || !result.equals("success")) { out.printf("{\"status\":100, \"message\":\"%s\"}", result == null ? "" : result); return;//from w w w .j av a 2s .c o m } String handleClass = fields.get("handleClass"); if (handleClass == null || handleClass.length() < 1) { out.write("{\"status\":100, \"message\":\"unkown handle class\"}"); return; } try { //handleClass Class<?> clazz = Class.forName(handleClass); FileUploadServlet servlet = (FileUploadServlet) clazz.newInstance(); out.write(servlet.run(fields, fileNames)); } catch (Exception e) { e.printStackTrace(); out.printf("{\"status\":100, \"message\":\"%s\"}", e.getMessage()); return; } /* if (handleClass != null && handleClass.equals("beans.service.LibraryFileUpload")) { out.write(new LibraryFileUpload().run(fields, fileNames)); return; } if (handleClass != null && handleClass.equals("beans.service.SharedobjectUpload")) { out.write(new SharedobjectUpload().run(fields, fileNames)); return; } */ }