List of usage examples for javax.servlet.http HttpServletRequest setCharacterEncoding
public void setCharacterEncoding(String env) throws UnsupportedEncodingException;
From source file:TwitterRetrieval.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter out;//from w w w . j a va 2 s . c o m try { // img stuff not req'd for source code html showing // all links relative // XXX // making these absolute till we work out the // addition of a PathInfo issue ConfigurationBuilder cb = new ConfigurationBuilder(); System.setProperty("twitter4j.http.httpClient", "twitter4j.internal.http.HttpClientImpl"); cb.setOAuthConsumerKey("56NAE9lQHSOZIGXRktd5Qw") .setOAuthConsumerSecret("zJjJrUUs1ubwKjtPOyYzrwBJzpwq7ud8Aryq1VhYH2E") .setOAuthAccessTokenURL("https://api.twitter.com/oauth/access_token") .setOAuthRequestTokenURL("https://api.twitter.com/oauth/request_token") .setOAuthAuthorizationURL("https://api.twitter.com/oauth/authorize") .setOAuthAccessToken("234742739-I1l0VGTTjRUbZrfH1jvKnTVFU9ZEvkxxUDpvsAJ2") .setOAuthAccessTokenSecret("jLe3imI3JiPgmHCatt6SqYgRAcX5q8s6z38oUrqMc"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); Query query = new Query(request.getParameter("q")); String tags = request.getParameter("tags"); String zone = request.getParameter("zone"); String users = request.getParameter("users"); Map<String, LatLon> latslongs = new HashMap(); String[] tagsArray = null; if (tags != null) { tagsArray = tags.split(","); } String[] userArray = null; if (users != null) { userArray = users.split(","); int count = userArray.length; usuarios = new String[count]; latitud = new String[count]; longitud = new String[count]; for (int i = 0; i < userArray.length; i++) { temp = userArray[i]; if (temp != null) { int hit1 = temp.indexOf("["); int hit2 = temp.indexOf(";"); int hit3 = temp.indexOf("]"); latslongs.put(temp.substring(0, hit1), new LatLon(temp.substring(hit1 + 1, hit2), temp.substring(hit2 + 1, hit3))); /* * usuarios[i] = temp.substring(0, hit1); latitud[i] = * temp.substring(hit1 + 1, hit2); longitud[i] = * temp.substring(hit2 + 1, hit3); */ } } } QueryResult result; result = twitter.search(query); List<Post> postList = new ArrayList(); List<PostType> postsList = new ArrayList(); Post solrPost; PostType post; //List<LinkType> links = new ArrayList(); List<ActionType> actions; ArrayList<User> toUsers = new ArrayList(); ArrayList<LinkType> links; int d; InputStream stream = getServletContext().getResourceAsStream("/WEB-INF/servlet.properties"); Properties props = null; if (props == null) { props = new Properties(); props.load(stream); } ZoneDao zoneDao = new ZoneDao(props.getProperty("db_host"), Integer.valueOf(props.getProperty("db_port")), props.getProperty("db_name")); PlaceDao placeDao = new PlaceDao(props.getProperty("db_host"), Integer.valueOf(props.getProperty("db_port")), props.getProperty("db_name")); Place place = null; org.zonales.tagsAndZones.objects.Zone zoneObj = zoneDao .retrieveByExtendedString(Utils.normalizeZone(zone)); for (Tweet tweet : (List<Tweet>) result.getTweets()) { d = MAX_TITLE_LENGTH; actions = new ArrayList(); try { actions.add(new ActionType("retweets", twitter.getRetweets(tweet.getId()).size())); actions.add(new ActionType("replies", twitter.getRelatedResults(tweet.getId()).getTweetsWithReply().size())); } catch (TwitterException ex) { Logger.getLogger(TwitterRetrieval.class.getName()).log(Level.SEVERE, "Error intentando obtener retweets o replies: {0}", new Object[] { ex }); } solrPost = new Post(); solrPost.setZone(new Zone(String.valueOf(zoneObj.getId()), zoneObj.getName(), zoneObj.getType().getName(), zoneObj.getExtendedString())); solrPost.setSource("Twitter"); solrPost.setId(String.valueOf(tweet.getId())); if (request.getParameter(tweet.getFromUser() + "Place") != null) { place = placeDao.retrieveByExtendedString(request.getParameter(tweet.getFromUser() + "Place")); } else { place = null; } User usersolr = new User(String.valueOf(tweet.getFromUserId()), tweet.getFromUser(), "http://twitter.com/#!/" + tweet.getFromUser(), tweet.getSource(), place != null ? new org.zonales.entities.Place(String.valueOf(place.getId()), place.getName(), place.getType().getName()) : null); if (users != null) { /* * for (int i = 0; i < usuarios.length; i++) { if * (tweet.getFromUser().equals(usuarios[i])) { * usersolr.setLatitude(Double.parseDouble(latitud[i])); * usersolr.setLongitude(Double.parseDouble(longitud[i])); } } */ //usersolr.setLatitude(Double.parseDouble(latslongs.get(tweet.getFromUser()).latitud)); //usersolr.setLongitude(Double.parseDouble(latslongs.get(tweet.getFromUser()).longitud)); } solrPost.setFromUser(usersolr); if (tweet.getToUser() != null) { toUsers.add(new User(String.valueOf(tweet.getToUserId()), tweet.getToUser(), null, tweet.getSource(), null)); solrPost.setToUsers(toUsers); } if (tweet.getText().length() > d) { while (d > 0 && tweet.getText().charAt(d - 1) != ' ') { d--; } } else { d = tweet.getText().length() - 1; } solrPost.setTitle(tweet.getText().substring(0, d) + (tweet.getText().length() > MAX_TITLE_LENGTH ? "..." : "")); solrPost.setText(tweet.getText()); //post.setLinks(new LinksType(links)); solrPost.setActions((ArrayList<ActionType>) actions); solrPost.setCreated(tweet.getCreatedAt().getTime()); solrPost.setModified(tweet.getCreatedAt().getTime()); solrPost.setRelevance( actions.size() == 2 ? actions.get(0).getCant() * 3 + actions.get(1).getCant() : 0); solrPost.setPostLatitude( tweet.getGeoLocation() != null ? tweet.getGeoLocation().getLatitude() : null); solrPost.setPostLongitude( tweet.getGeoLocation() != null ? tweet.getGeoLocation().getLongitude() : null); links = new ArrayList<LinkType>(); links.add(new LinkType("avatar", tweet.getProfileImageUrl())); if (tweet.getText() != null && getLinks(tweet.getText()) != null) { links.addAll(getLinks(tweet.getText())); } if (solrPost.getLinks() == null) { solrPost.setLinks(new ArrayList<LinkType>()); } solrPost.setLinks(links); if (tagsArray != null && tagsArray.length > 0) { solrPost.setTags(new ArrayList<String>(Arrays.asList(tagsArray))); } solrPost.setExtendedString(WordUtils.capitalize((solrPost.getFromUser().getPlace() != null ? solrPost.getFromUser().getPlace().getName() + ", " : "") + solrPost.getZone().getExtendedString().replace("_", " "))); postList.add(solrPost); post = new PostType(); post.setZone(new Zone(String.valueOf(zoneObj.getId()), zoneObj.getName(), zoneObj.getType().getName(), zoneObj.getExtendedString())); post.setSource("Twitter"); post.setId(String.valueOf(tweet.getId())); User user = new User(String.valueOf(tweet.getFromUserId()), tweet.getFromUser(), "http://twitter.com/#!/" + tweet.getFromUser(), tweet.getSource(), place != null ? new org.zonales.entities.Place(String.valueOf(place.getId()), place.getName(), place.getType().getName()) : null); if (users != null) { /* * for (int i = 0; i < usuarios.length; i++) { if * (tweet.getFromUser().equals(usuarios[i])) { * user.setLatitude(Double.parseDouble(latitud[i])); * user.setLongitude(Double.parseDouble(longitud[i])); } } */ //user.setLatitude(Double.parseDouble(latslongs.get(tweet.getFromUser()).latitud)); //user.setLongitude(Double.parseDouble(latslongs.get(tweet.getFromUser()).longitud)); } post.setFromUser(user); if (tweet.getToUser() != null) { toUsers.add(new User(String.valueOf(tweet.getToUserId()), tweet.getToUser(), null, tweet.getSource(), null)); post.setToUsers(new ToUsersType(toUsers)); } post.setTitle(tweet.getText().substring(0, d) + (tweet.getText().length() > MAX_TITLE_LENGTH ? "..." : "")); post.setText(tweet.getText()); //post.setLinks(new LinksType(links)); post.setActions(new ActionsType(actions)); post.setCreated(String.valueOf(tweet.getCreatedAt().getTime())); post.setModified(String.valueOf(tweet.getCreatedAt().getTime())); post.setRelevance( actions.size() == 2 ? actions.get(0).getCant() * 3 + actions.get(1).getCant() : 0); post.setPostLatitude(tweet.getGeoLocation() != null ? tweet.getGeoLocation().getLatitude() : null); post.setPostLongitude( tweet.getGeoLocation() != null ? tweet.getGeoLocation().getLongitude() : null); links = new ArrayList<LinkType>(); links.add(new LinkType("avatar", tweet.getProfileImageUrl())); post.setLinks(new LinksType(getLinks(tweet.getText()))); if (tagsArray != null && tagsArray.length > 0) { post.setTags(new TagsType(Arrays.asList(tagsArray))); } postsList.add(post); } PostsType posts = new PostsType(postsList); Gson gson = new Gson(); if ("xml".equalsIgnoreCase(request.getParameter("format"))) { response.setContentType("application/xml"); out = response.getWriter(); try { for (PostType postIt : posts.getPost()) { postIt.setVerbatim(gson.toJson(postIt)); } Twitter2XML(posts, out); } catch (Exception ex) { Logger.getLogger(TwitterRetrieval.class.getName()).log(Level.SEVERE, null, ex); } } else { response.setContentType("text/javascript"); out = response.getWriter(); out.println("{post: " + gson.toJson(postList) + "}"); } } catch (TwitterException ex) { Logger.getLogger(TwitterRetrieval.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.apache.marmotta.platform.sparql.webservices.SparqlWebService.java
/** * Execute a SPARQL 1.1 Update request using update via POST directly; * see details at http://www.w3.org/TR/sparql11-protocol/\#update-operation * // w w w .j a v a 2 s . com * @param request the servlet request (to retrieve the SPARQL 1.1 Update query passed in the * body of the POST request) * @HTTP 200 in case the update was carried out successfully * @HTTP 400 in case the update query is missing or invalid * @HTTP 500 in case the update was not successful * @return empty content in case the update was successful, the error message in case an error * occurred */ @POST @Path(UPDATE) @Consumes("application/sparql-update") public Response updatePostDirectly(@Context HttpServletRequest request, @QueryParam("output") String resultType) { try { if (request.getCharacterEncoding() == null) { request.setCharacterEncoding("utf-8"); } String q = CharStreams.toString(request.getReader()); return update(q, resultType, request); } catch (IOException e) { return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build(); } }
From source file:com.openkm.servlet.admin.ConfigServlet.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 filter = WebUtils.getString(request, "filter"); String userId = request.getRemoteUser(); updateSessionManager(request);//w w w . j av a2 s . c om try { if (action.equals("create")) { create(userId, types, request, response); } else if (action.equals("edit")) { edit(userId, types, request, response); } else if (action.equals("delete")) { delete(userId, types, request, response); } else if (action.equals("view")) { view(userId, request, response); } else if (action.equals("check")) { check(userId, request, response); } else if (action.equals("export")) { export(userId, request, response); } else { list(userId, filter, request, response); } } catch (DatabaseException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } }
From source file:com.concursive.connect.web.rss.servlets.FeedServlet.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { try {//w w w . j ava2 s .co m request.setCharacterEncoding("UTF-8"); } catch (Exception e) { LOG.warn("Unsupported encoding"); } Connection db = null; try { response.setContentType(MIME_TYPE); ApplicationPrefs prefs = (ApplicationPrefs) getServletContext() .getAttribute(Constants.APPLICATION_PREFS); String url = "http://" + RequestUtils.getServerUrl(request); List entries = new ArrayList(); SyndEntry entry; SyndContent description; // Everything is ready, now check the username/password db = getConnection(getServletContext()); java.util.Date publishDate = null; // Can pull from a cache or rebuild the news list... String path = request.getRequestURI(); // Generate the RSS and replace the cache for all public projects SyndFeed feed = new SyndFeedImpl(); if (path.endsWith("/rss.xml")) { // @todo /feed/products/name_of_product/rss.xml // Use the purpose of the site for determining what is included in the feed String purpose = prefs.get(ApplicationPrefs.PURPOSE); // The intranet feed is not a public feed and requires login int userId = -1; if ("intranet".equals(purpose) && "true".equals(prefs.get(ApplicationPrefs.INFORMATION_IS_SENSITIVE))) { // Check credentials boolean authenticated = WebdavManager.checkAuthentication(request); if (!authenticated) { WebdavManager.askForAuthentication(response); return; } userId = WebdavManager.validateUser(db, request); if (userId == -1) { WebdavManager.askForAuthentication(response); return; } } // Check to see which public feed is requested if (path.endsWith("/feed/rss.xml")) { // This is the main website feed feed = FeedUtils.loadFeed("/rss.xml," + purpose, url); feed.setTitle(prefs.get("TITLE")); feed.setDescription(prefs.get("TITLE") + " feed"); } else { // Check to see which website category feed is requested ProjectCategoryList projectCategoryList = new ProjectCategoryList(); projectCategoryList.setTopLevelOnly(true); projectCategoryList.setEnabled(true); if (userId == -1) { projectCategoryList.setSensitive(Constants.FALSE); } projectCategoryList.buildList(db); for (ProjectCategory projectCategory : projectCategoryList) { String normalizedCategoryName = projectCategory.getNormalizedCategoryName(); if (path.indexOf(normalizedCategoryName) != -1) { String requestedFeed = path.substring(path.indexOf("/feed/") + "/feed/".length(), path.indexOf(".xml")) + ".xml"; LOG.debug("Requested feed: " + requestedFeed); feed = FeedUtils.loadFeed(requestedFeed + "," + purpose, url); feed.setTitle(prefs.get("TITLE") + " - " + projectCategory.getLabel()); feed.setDescription(prefs.get("TITLE") + " - " + projectCategory.getLabel() + " feed"); break; } } } // No feed was found if (feed == null) { return; } } else { boolean authenticated = WebdavManager.checkAuthentication(request); if (!authenticated) { WebdavManager.askForAuthentication(response); return; } int userId = WebdavManager.validateUser(db, request); if (userId == -1) { WebdavManager.askForAuthentication(response); return; } if (path.endsWith("/news.xml") || path.endsWith("/blog.xml")) { feed.setTitle(prefs.get("TITLE") + " - Blog Rollup"); feed.setDescription(prefs.get("TITLE") + " personalized blog rollup"); BlogPostList newsList = new BlogPostList(); newsList.setLastNews(5); newsList.setForUser(userId); //Calendar cal = Calendar.getInstance(); // 14 Days //cal.add(Calendar.DAY_OF_MONTH, -30); //Timestamp alertRangeStart = new Timestamp(cal.getTimeInMillis()); //newsList.setAlertRangeStart(alertRangeStart); newsList.setCurrentNews(Constants.TRUE); newsList.buildList(db); Iterator i = newsList.iterator(); while (i.hasNext()) { BlogPost thisArticle = (BlogPost) i.next(); Project thisProject = ProjectUtils.loadProject(thisArticle.getProjectId()); entry = new SyndEntryImpl(); entry.setTitle(thisArticle.getSubject()); entry.setPublishedDate(thisArticle.getStartDate()); if (publishDate == null || thisArticle.getStartDate().after(publishDate)) { publishDate = thisArticle.getStartDate(); } entry.setAuthor(UserUtils.getUserName(thisArticle.getEnteredBy())); description = new SyndContentImpl(); description.setType("text/html"); description.setValue(thisArticle.getIntro()); entry.setLink(url + "/show/" + thisProject.getUniqueId() + "/post/" + thisArticle.getId()); entry.setDescription(description); entries.add(entry); } } if (path.endsWith("/discussion.xml")) { feed.setTitle(prefs.get("TITLE") + " - Discussion Rollup"); feed.setDescription(prefs.get("TITLE") + " personalized discussion rollup"); TopicList topicList = new TopicList(); topicList.setForUser(userId); PagedListInfo pagedList = new PagedListInfo(); pagedList.setColumnToSortBy("i.last_reply_date"); pagedList.setSortOrder("desc"); pagedList.setItemsPerPage(10); topicList.setPagedListInfo(pagedList); topicList.buildList(db); Iterator i = topicList.iterator(); while (i.hasNext()) { Topic thisTopic = (Topic) i.next(); Project thisProject = ProjectUtils.loadProject(thisTopic.getProjectId()); entry = new SyndEntryImpl(); entry.setTitle(thisTopic.getSubject()); entry.setPublishedDate(thisTopic.getReplyDate()); if (publishDate == null || thisTopic.getReplyDate().after(publishDate)) { publishDate = thisTopic.getReplyDate(); } if (thisTopic.getReplyBy() > -1) { entry.setAuthor(UserUtils.getUserName(thisTopic.getReplyBy())); } else if (thisTopic.getReplyBy() == -1) { entry.setAuthor(UserUtils.getUserName(thisTopic.getEnteredBy())); } description = new SyndContentImpl(); description.setType("text/html"); if (thisTopic.getReplyBy() == -1) { // This is the first posting description.setValue(StringUtils.toHtml(thisTopic.getBody())); } else { // This is a reply // TODO: Load the reply description.setValue(StringUtils.toHtml("A reply has been posted.")); } entry.setLink(url + "/show/" + thisProject.getUniqueId() + "/topic/" + thisTopic.getId() + "?resetList=true&modified=" + thisTopic.getReplyDate().getTime()); entry.setDescription(description); entries.add(entry); } } if (path.endsWith("/documents.xml")) { feed.setTitle(prefs.get("TITLE") + " - Documents Rollup"); feed.setDescription(prefs.get("TITLE") + " personalized document rollup"); FileItemList fileItemList = new FileItemList(); fileItemList.setLinkModuleId(Constants.PROJECTS_FILES); fileItemList.setForProjectUser(userId); PagedListInfo pagedList = new PagedListInfo(); pagedList.setColumnToSortBy("f.modified"); pagedList.setSortOrder("desc"); pagedList.setItemsPerPage(10); fileItemList.setPagedListInfo(pagedList); fileItemList.buildList(db); Iterator i = fileItemList.iterator(); while (i.hasNext()) { FileItem fileItem = (FileItem) i.next(); entry = new SyndEntryImpl(); entry.setTitle(fileItem.getSubject()); entry.setPublishedDate(fileItem.getModified()); if (publishDate == null || fileItem.getModified().after(publishDate)) { publishDate = fileItem.getModified(); } entry.setAuthor(UserUtils.getUserName(fileItem.getModifiedBy())); description = new SyndContentImpl(); description.setType("text/html"); description.setValue("<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n" + " <tr>\n" + " <td valign=\"top\">\n" + " " + fileItem.getImageTag("-23", url) + "\n" + " </td>\n" + " <td>\n" + " " + StringUtils.toHtml(fileItem.getClientFilename()) + " " + fileItem.getVersion() + ", " + fileItem.getRelativeSize() + "k\n" + " </td>\n" + " </tr>\n" + " </table>"); entry.setLink( url + "/ProjectManagementFiles.do?command=Details&pid=" + fileItem.getLinkItemId() + "&fid=" + fileItem.getId() + "&folderId=" + fileItem.getFolderId()); entry.setDescription(description); entries.add(entry); } } if (path.endsWith("/wiki.xml")) { feed.setTitle(prefs.get("TITLE") + " - Wiki Rollup"); feed.setDescription(prefs.get("TITLE") + " personalized wiki entry rollup"); WikiList wikiList = new WikiList(); wikiList.setForUser(userId); PagedListInfo pagedList = new PagedListInfo(); pagedList.setColumnToSortBy("w.modified"); pagedList.setSortOrder("desc"); pagedList.setItemsPerPage(10); wikiList.setPagedListInfo(pagedList); wikiList.buildList(db); Iterator i = wikiList.iterator(); while (i.hasNext()) { Wiki thisWiki = (Wiki) i.next(); entry = new SyndEntryImpl(); Project thisProject = ProjectUtils.loadProject(thisWiki.getProjectId()); if (thisWiki.getSubjectLink() == null || "".equals(thisWiki.getSubjectLink().trim())) { entry.setTitle(thisProject.getTitle() + ": Home"); } else { entry.setTitle(thisWiki.getSubject()); } entry.setPublishedDate(thisWiki.getModified()); if (publishDate == null || thisWiki.getModified().after(publishDate)) { publishDate = thisWiki.getModified(); } entry.setAuthor(UserUtils.getUserName(thisWiki.getModifiedBy())); description = new SyndContentImpl(); description.setType("text/html"); entry.setLink(url + "/show/" + thisProject.getUniqueId() + "/wiki" + (StringUtils.hasText(thisWiki.getSubjectLink()) ? "/" + thisWiki.getSubjectLink() : "") + "?modified=" + thisWiki.getModified().getTime()); entry.setDescription(description); entries.add(entry); } } // Prepare the feed classes before using the database connection... //rss_0.90, rss_0.91, rss_0.92, rss_0.93, rss_0.94, rss_1.0 rss_2.0 or atom_0.3 if (publishDate == null) { publishDate = new java.util.Date(); } feed.setEntries(entries); } // Output the feed SyndFeedOutput output = new SyndFeedOutput(); feed.setFeedType("rss_2.0"); feed.setPublishedDate(publishDate); feed.setLink(url); output.output(feed, response.getWriter()); } catch (Exception ex) { String msg = COULD_NOT_GENERATE_FEED_ERROR; log(msg, ex); ex.printStackTrace(System.out); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg); } finally { freeConnection(db, getServletContext()); } }
From source file:com.openkm.servlet.admin.DbRepositoryViewServlet.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doPost({}, {})", request, response); request.setCharacterEncoding("UTF-8"); String action = WebUtils.getString(request, "action"); String path = WebUtils.getString(request, "path"); String uuid = WebUtils.getString(request, "uuid"); updateSessionManager(request);/* w ww . j a v a2 s. co m*/ try { if (uuid != null && !uuid.isEmpty()) { path = NodeBaseDAO.getInstance().getPathFromUuid(uuid); } else if (path != null && !path.isEmpty()) { uuid = NodeBaseDAO.getInstance().getUuidFromPath(path); } if ("editPersist".equals(action)) { editPersist(uuid, path, request, response); list(uuid, path, request, response); } } catch (PathNotFoundException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (AccessDeniedException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (RepositoryException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (ParseException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (DatabaseException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } }
From source file:com.icb123.Controller.BusinessController.java
@RequestMapping(value = "/appoint") public void customerAppointment(HttpServletRequest request, HttpServletResponse response) { try {//w w w . j ava 2s .c om request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); Constants.root = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); String sysRootPath = request.getSession().getServletContext().getRealPath("\\"); SystemStaticArgsSet.setSysRootPath(sysRootPath); String requestType = request.getParameter("requestType") == null ? "" : request.getParameter("requestType"); String userCode = request.getParameter("userCode") == null ? "" : request.getParameter("userCode"); String openid = request.getParameter("openid") == null ? "" : request.getParameter("openid"); //openid="111111"; if (StringUtils.isBlank(openid) && StringUtils.isNotBlank(userCode)) { openid = WeixinUntil.getUserOoenid(userCode); } if (weixinCustomerManager.findByOpenid(openid) == null) { String accessToken = WeixinUntil.getAccessToken(); WeixinCustomer wx = customerBusinessManager.getCustomerInfo(openid, accessToken, ""); weixinCustomerManager.save(wx); } //System.out.println(PropertiesUtils.getValueByKey("token")); Employee emp = (Employee) request.getSession().getAttribute("Employee"); String empCode = ""; if (emp != null) { empCode = emp.getCode(); } else { if (!"".equals(openid)) { empCode = employeeManager.findEmployeeCodeByOpenid(openid); } } if ("1".equals(requestType)) {// String paramObj = request.getParameter("paramObj"); JSONObject json = JSONObject.fromObject(paramObj); JSONArray arr = (JSONArray) json.get("service"); String[] serviceArray = new String[arr.size()]; serviceArray = (String[]) arr.toArray(serviceArray); Map<String, String> result = null; if (StringUtils.isNotBlank((String) json.get("userCode"))) { openid = WeixinUntil.getUserOoenid((String) json.get("userCode")); } else { openid = null; } try { result = businessManager.appointmentMaintenance((String) json.get("date"), (String) json.get("timeCode"), (String) json.get("mobile"), (String) json.get("name"), openid, (String) json.get("carCode"), (String) json.get("license"), (String) json.get("code"), (String) json.get("totalPrice"), (String) json.get("address"), (String) json.get("remark"), (String) json.get("appTypeCode"), (String) json.get("type"), serviceArray); } catch (Exception e) { outPutErrorInfor(BusinessController.class.getName(), "", e); } OutputUtil.outPutJsonObject(response, result); } else if ("2".equals(requestType)) {// String status = request.getParameter("status") == null ? "" : request.getParameter("status"); String currentPageStr = request.getParameter("currentPage") == null ? "" : request.getParameter("currentPage"); String sizeStr = request.getParameter("pageSize") == null ? "" : request.getParameter("pageSize"); String ctime = request.getParameter("ctime") == null ? "" : request.getParameter("ctime"); String mobile = request.getParameter("smobile") == null ? "" : request.getParameter("smobile"); String atime = request.getParameter("atime") == null ? "" : request.getParameter("atime"); try { Map<String, String> argMap = new HashMap<String, String>(); argMap.put("status", status); if (StringUtils.isNotBlank(currentPageStr) && StringUtils.isNotBlank(sizeStr)) { int currentPage = Integer.valueOf(currentPageStr); int size = Integer.valueOf(sizeStr); int begin = (currentPage - 1) * size; argMap.put("size", size + ""); argMap.put("begin", begin + ""); argMap.put("currentPage", currentPageStr); argMap.put("ctime", ctime); argMap.put("atime", atime); argMap.put("mobile", mobile); } PageBean page = businessManager.selectAppointment(argMap); OutputUtil.outPutJsonObject(response, page); } catch (Exception e) { outPutErrorInfor(BusinessController.class.getName(), "?", e); } } else if ("3".equals(requestType)) {// String appcode = request.getParameter("code") == null ? "" : request.getParameter("code"); Map map = businessManager.findDetailedAppointment(appcode); OutputUtil.outPutJsonObject(response, map); } else if ("4".equals(requestType)) {// String paramObj = request.getParameter("paramObj"); JSONObject json = JSONObject.fromObject(paramObj); JSONArray arr = (JSONArray) json.get("service"); String[] serviceArray = new String[arr.size()]; serviceArray = (String[]) arr.toArray(serviceArray); Map<String, String> result = null; try { result = businessManager.appointmentConfirm((String) json.get("timeCode"), (String) json.get("date"), (String) json.get("time"), (String) json.get("carCode"), (String) json.get("license"), (String) json.get("haveCar"), (String) json.get("modelsCode"), (String) json.get("modelsStr"), (String) json.get("cusCode"), (String) json.get("mobile"), (String) json.get("name"), (String) json.get("address"), (String) json.get("code"), (String) json.get("remark"), (String) json.get("totalPrice"), serviceArray, emp.getCode(), (String) json.get("status"), (String) json.get("wxCode")); } catch (Exception e) { outPutErrorInfor(BusinessController.class.getName(), "", e); } OutputUtil.outPutJsonObject(response, result); } else if ("5".equals(requestType)) {//? String appcode = request.getParameter("code") == null ? "" : request.getParameter("code"); String reason = request.getParameter("reason") == null ? "" : request.getParameter("reason"); Map<String, String> result = businessManager.appointmentCancel(appcode, empCode, reason); OutputUtil.outPutJsonObject(response, result); } else if ("6".equals(requestType)) {//? String date = request.getParameter("date") == null ? "" : request.getParameter("date"); String time = request.getParameter("time") == null ? "" : request.getParameter("time"); List<Team> list = businessManager.findFreeTeam(date, time); OutputUtil.outPutJsonArrary(response, list); } else if ("7".equals(requestType)) {// String appCode = request.getParameter("appCode") == null ? "" : request.getParameter("appCode"); String teamCode = request.getParameter("teamCode") == null ? "" : request.getParameter("teamCode"); String[] empArr = request.getParameterValues("emp"); Map<String, String> result = businessManager.distributeWork(appCode, empCode, teamCode, empArr); OutputUtil.outPutJsonObject(response, result); } else if ("8".equals(requestType)) {// String currentPageStr = request.getParameter("currentPage") == null ? "" : request.getParameter("currentPage"); String sizeStr = request.getParameter("pageSize") == null ? "" : request.getParameter("pageSize"); try { Map<String, String> argMap = new HashMap<String, String>(); argMap.put("empCode", empCode); if (StringUtils.isNotBlank(currentPageStr) && StringUtils.isNotBlank(sizeStr)) { int currentPage = Integer.valueOf(currentPageStr); int size = Integer.valueOf(sizeStr); int begin = (currentPage - 1) * size; argMap.put("size", size + ""); argMap.put("begin", begin + ""); argMap.put("currentPage", currentPageStr); } PageBean page = businessManager.selectPersonalAppointment(argMap); OutputUtil.outPutJsonObject(response, page); } catch (Exception e) { outPutErrorInfor(BusinessController.class.getName(), "", e); } } else if ("9".equals(requestType)) {// String empcode = request.getParameter("code") == null ? "" : request.getParameter("code"); String position = request.getParameter("position") == null ? "" : request.getParameter("position"); List<Employee> list = businessManager.findFreeEmp(empcode, position); OutputUtil.outPutJsonArrary(response, list); } else if ("10".equals(requestType)) {//? String appcode = request.getParameter("code") == null ? "" : request.getParameter("code"); Map<String, String> result = businessManager.daleteDistributeWork(appcode, empCode); OutputUtil.outPutJsonObject(response, result); } else if ("11".equals(requestType)) {//? String appcode = request.getParameter("code") == null ? "" : request.getParameter("code"); List<WorkRecord> list = workRecordManager.findByAppCode(appcode); OutputUtil.outPutJsonArrary(response, list); } else if ("12".equals(requestType)) {//??? String mobile = request.getParameter("mobile") == null ? "" : request.getParameter("mobile"); Map<String, String> result = sendManager.mobileValidate(mobile); OutputUtil.outPutJsonObject(response, result); } else if ("13".equals(requestType)) {//? String mobile = request.getParameter("mobile") == null ? "" : request.getParameter("mobile"); String validate = request.getParameter("validate") == null ? "" : request.getParameter("validate"); Map<String, String> result = businessManager.mobileValidate(mobile, validate);//? OutputUtil.outPutJsonObject(response, result); } else if ("14".equals(requestType)) {//?? /*String model=request.getParameter("model") == null ? "": request.getParameter("model"); String appcode=request.getParameter("code") == null ? "": request.getParameter("code"); String weixinCode=request.getParameter("weixinCode") == null ? "": request.getParameter("weixinCode"); Map<String, String> result=businessManager.writeAccessoriesModel(appcode,model,weixinCode); OutputUtil.outPutJsonObject(response, result);*/ } else if ("15".equals(requestType)) {// String appcode = request.getParameter("code") == null ? "" : request.getParameter("code"); String vipCondition = request.getParameter("condition") == null ? "" : request.getParameter("condition"); Map<String, String> result = businessManager.finishAppointment(appcode, vipCondition); OutputUtil.outPutJsonObject(response, result); } else if ("16".equals(requestType)) {//?? String kfpwd = "qweasd"; String validate = request.getParameter("code") == null ? "" : request.getParameter("code"); Map<String, String> result = new HashMap<String, String>(); if (validate.equals(kfpwd)) { result.put("flag", "1"); } else { result.put("flag", "-1"); } OutputUtil.outPutJsonObject(response, result); } else if ("17".equals(requestType)) {//??? String mobile = request.getParameter("mobile") == null ? "" : request.getParameter("mobile"); List<Map<String, Object>> result = businessManager .searchCustomerPensonalAppointmentByMobile(mobile); OutputUtil.outPutJsonArrary(response, result); } else if ("18".equals(requestType)) { //? response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "No-cache"); response.setDateHeader("Expires", 0); //? response.setContentType("image/jpeg"); IdentifyingImg img = new IdentifyingImg(); ImageIO.write(img.creat(), "JPEG", response.getOutputStream()); } else if ("19".equals(requestType)) {//?? Map<String, Object> map = weixinCustomerManager.findCustomerInfo(openid); OutputUtil.outPutJsonObject(response, map); } else if ("20".equals(requestType)) {//???? List<Map> result = businessManager.findCurrentAppByOpenid(openid); OutputUtil.outPutJsonArrary(response, result); } else if ("21".equals(requestType)) {//??? //List<Map> result=businessManager.searchCustomerPensonalAppointmentByOpenid(openid); List<CustomerCar> result = businessManager.findHistoryCar(openid); OutputUtil.outPutJsonArrary(response, result); } else if ("22".equals(requestType)) {//?? Map<String, String> result = new HashMap<String, String>(); String path = weixinCustomerManager.creatEwmByWeixinCustomer(openid); result.put("path", path); OutputUtil.outPutJsonObject(response, result); } else if ("23".equals(requestType)) {//??? Map<String, String> result = null; Customer cus = customerManager.findCustomerByOpenid(openid); if (cus != null) { result = new HashMap<String, String>(); result.put("name", cus.getName()); result.put("mobile", cus.getMobile()); } OutputUtil.outPutJsonObject(response, result); } else if ("24".equals(requestType)) {//?? String name = request.getParameter("name") == null ? "" : request.getParameter("name"); String mobile = request.getParameter("mobile") == null ? "" : request.getParameter("mobile"); Map<String, String> result = weixinCustomerManager.saveCustomerInfo(openid, name, mobile); OutputUtil.outPutJsonObject(response, result); } else if ("25".equals(requestType)) {//?? List<Map> result = businessManager.findCurrentCar(openid); OutputUtil.outPutJsonArrary(response, result); } else if ("26".equals(requestType)) {//? List<Map<String, String>> list = weixinCustomerManager.findConsumptionRecordByOpenid(openid); OutputUtil.outPutJsonArrary(response, list); } else if ("27".equals(requestType)) {//?? String busnessType = request.getParameter("type") == null ? "" : request.getParameter("type"); String totalPrice = request.getParameter("totalPrice") == null ? "" : request.getParameter("totalPrice"); double pay = integralManager.maxOutIntegral(openid, Integer.valueOf(busnessType), Double.valueOf(totalPrice)); Map<String, String> map = new HashMap<String, String>(); map.put("pay", (int) pay + ""); OutputUtil.outPutJsonObject(response, map); } else if ("28".equals(requestType)) {// String code = request.getParameter("code") == null ? "" : request.getParameter("code"); String busnessType = request.getParameter("type") == null ? "" : request.getParameter("type"); String pay = request.getParameter("pay") == null ? "" : request.getParameter("pay"); Map<String, String> map = businessManager.integralPay(code, openid, busnessType, pay); OutputUtil.outPutJsonObject(response, map); } else if ("29".equals(requestType)) {//? String date = request.getParameter("date") == null ? "" : request.getParameter("date"); List<AppointmentTime> list = businessManager.findAppTime(date); OutputUtil.outPutJsonArrary(response, list); } else if ("30".equals(requestType)) {//? String code = request.getParameter("code") == null ? "" : request.getParameter("code"); String score = request.getParameter("scorce") == null ? "" : request.getParameter("scorce"); Map<String, String> result = businessManager.saveCustomerScore(code, score); OutputUtil.outPutJsonObject(response, result); } else if ("31".equals(requestType)) {//? String code = request.getParameter("weixinCode") == null ? "" : request.getParameter("weixinCode"); Map<String, Object> result = weixinCustomerManager.openGiftView(code); OutputUtil.outPutJsonObject(response, result); } else if ("32".equals(requestType)) {// String code = request.getParameter("weixinCode") == null ? "" : request.getParameter("weixinCode"); String accept = request.getParameter("accept") == null ? "" : request.getParameter("accept"); List<WeixinAcceptRecord> list = weixinCustomerManager.acceptGift(code, accept); OutputUtil.outPutJsonArrary(response, list); } else if ("33".equals(requestType)) {//?? String carCdoe = request.getParameter("code") == null ? "" : request.getParameter("code"); List<Map> list = businessManager.findHistoryAppByCarCode(carCdoe); OutputUtil.outPutJsonArrary(response, list); } else if ("100".equals(requestType)) {//??? String paramObj = request.getParameter("paramObj") == null ? "" : request.getParameter("paramObj"); JSONObject json = JSONObject.fromObject(paramObj); Map<String, String> result = businessManager.inPutFinishInfo(json, emp.getCode()); OutputUtil.outPutJsonObject(response, result); } else if ("101".equals(requestType)) {// String appCode = request.getParameter("appCode") == null ? "" : request.getParameter("appCode"); List<CustomerCarSituation> list = customerManager.findByAppCode(appCode); Map<String, List<CustomerCarSituation>> result = new HashMap<String, List<CustomerCarSituation>>(); result.put("ccs", list); OutputUtil.outPutJsonObject(response, result); } else if ("102".equals(requestType)) {//? String position = request.getParameter("position") == null ? "" : request.getParameter("position"); List<Employee> list = employeeManager.findEmployeeByPosition(position); OutputUtil.outPutJsonArrary(response, list); } else if ("103".equals(requestType)) {//?? String appCode = request.getParameter("appCode") == null ? "" : request.getParameter("appCode"); List<WorkRecord> list = workRecordManager.findByAppCode(appCode); OutputUtil.outPutJsonArrary(response, list); } else if ("104".equals(requestType)) {// List<Team> list = carMaintenanceManager.findAllTeam(); OutputUtil.outPutJsonArrary(response, list); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block outPutErrorInfor(BusinessController.class.getName(), "?", e); } catch (IOException e) { outPutErrorInfor(BusinessController.class.getName(), "?", e); } }
From source file:com.ikon.servlet.admin.OmrServlet.java
@SuppressWarnings("unchecked") public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doPost({}, {})", request, response); request.setCharacterEncoding("UTF-8"); String action = ""; String userId = request.getRemoteUser(); updateSessionManager(request);/*from w w w .java2 s . com*/ try { if (ServletFileUpload.isMultipartContent(request)) { String fileName = null; InputStream is = null; FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request); Set<String> properties = new HashSet<String>(); Omr om = new Omr(); for (Iterator<FileItem> it = items.iterator(); it.hasNext();) { FileItem item = it.next(); if (item.isFormField()) { if (item.getFieldName().equals("action")) { action = item.getString("UTF-8"); } else if (item.getFieldName().equals("om_id")) { om.setId(Integer.parseInt(item.getString("UTF-8"))); } else if (item.getFieldName().equals("om_name")) { om.setName(item.getString("UTF-8")); } else if (item.getFieldName().equals("om_properties")) { properties.add(item.getString("UTF-8")); } else if (item.getFieldName().equals("om_active")) { om.setActive(true); } } else { is = item.getInputStream(); fileName = item.getName(); } } om.setProperties(properties); if (action.equals("create") || action.equals("edit")) { // Store locally template file to be used later if (is != null && is.available() > 0) { // Case update only name byte[] data = IOUtils.toByteArray(is); File tmp = FileUtils.createTempFile(); FileOutputStream fos = new FileOutputStream(tmp); IOUtils.write(data, fos); IOUtils.closeQuietly(fos); // Store template file om.setTemplateFileName(FilenameUtils.getName(fileName)); om.setTemplateFileMime(MimeTypeConfig.mimeTypes.getContentType(fileName)); om.setTemplateFilContent(data); IOUtils.closeQuietly(is); // Create training files Map<String, File> trainingMap = OMRHelper.trainingTemplate(tmp); File ascFile = trainingMap.get(OMRHelper.ASC_FILE); File configFile = trainingMap.get(OMRHelper.CONFIG_FILE); // Store asc file om.setAscFileName(om.getTemplateFileName() + ".asc"); om.setAscFileMime(MimeTypeConfig.MIME_TEXT); is = new FileInputStream(ascFile); om.setAscFileContent(IOUtils.toByteArray(is)); IOUtils.closeQuietly(is); // Store config file om.setConfigFileName(om.getTemplateFileName() + ".config"); om.setConfigFileMime(MimeTypeConfig.MIME_TEXT); is = new FileInputStream(configFile); om.setConfigFileContent(IOUtils.toByteArray(is)); IOUtils.closeQuietly(is); // Delete temporal files FileUtils.deleteQuietly(tmp); FileUtils.deleteQuietly(ascFile); FileUtils.deleteQuietly(configFile); } if (action.equals("create")) { long id = OmrDAO.getInstance().create(om); // Activity log UserActivity.log(userId, "ADMIN_OMR_CREATE", Long.toString(id), null, om.toString()); } else if (action.equals("edit")) { OmrDAO.getInstance().updateTemplate(om); om = OmrDAO.getInstance().findByPk(om.getId()); // Activity log UserActivity.log(userId, "ADMIN_OMR_EDIT", Long.toString(om.getId()), null, om.toString()); } list(userId, request, response); } else if (action.equals("delete")) { OmrDAO.getInstance().delete(om.getId()); // Activity log UserActivity.log(userId, "ADMIN_OMR_DELETE", Long.toString(om.getId()), null, null); list(userId, request, response); } else if (action.equals("editAsc")) { Omr omr = OmrDAO.getInstance().findByPk(om.getId()); omr.setAscFileContent(IOUtils.toByteArray(is)); omr.setAscFileMime(MimeTypeConfig.MIME_TEXT); omr.setAscFileName(omr.getTemplateFileName() + ".asc"); OmrDAO.getInstance().update(omr); omr = OmrDAO.getInstance().findByPk(om.getId()); IOUtils.closeQuietly(is); // Activity log UserActivity.log(userId, "ADMIN_OMR_EDIT_ASC", Long.toString(om.getId()), null, null); list(userId, request, response); } else if (action.equals("editFields")) { Omr omr = OmrDAO.getInstance().findByPk(om.getId()); omr.setFieldsFileContent(IOUtils.toByteArray(is)); omr.setFieldsFileMime(MimeTypeConfig.MIME_TEXT); omr.setFieldsFileName(omr.getTemplateFileName() + ".fields"); OmrDAO.getInstance().update(omr); omr = OmrDAO.getInstance().findByPk(om.getId()); IOUtils.closeQuietly(is); // Activity log UserActivity.log(userId, "ADMIN_OMR_EDIT_FIELDS", Long.toString(om.getId()), null, null); list(userId, request, response); } else if (action.equals("check")) { File form = FileUtils.createTempFile(); OutputStream formFile = new FileOutputStream(form); formFile.write(IOUtils.toByteArray(is)); IOUtils.closeQuietly(formFile); formFile.close(); Map<String, String> results = OMRHelper.process(form, om.getId()); FileUtils.deleteQuietly(form); IOUtils.closeQuietly(is); UserActivity.log(userId, "ADMIN_OMR_CHECK_TEMPLATE", Long.toString(om.getId()), null, null); results(userId, request, response, action, results, om.getId()); } } } catch (DatabaseException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (FileUploadException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (OMRException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (InvalidFileStructureException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (InvalidImageIndexException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (UnsupportedTypeException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (MissingParameterException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (WrongParameterException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } }
From source file:com.openkm.servlet.admin.StampServlet.java
@SuppressWarnings("unchecked") public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doPost({}, {})", request, response); request.setCharacterEncoding("UTF-8"); String action = WebUtils.getString(request, "action"); Session session = null;/*www. j a v a 2 s.co m*/ updateSessionManager(request); try { if (ServletFileUpload.isMultipartContent(request)) { session = JCRUtils.getSession(); InputStream is = null; FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request); StampImage si = new StampImage(); for (Iterator<FileItem> it = items.iterator(); it.hasNext();) { FileItem item = it.next(); if (item.isFormField()) { if (item.getFieldName().equals("action")) { action = item.getString("UTF-8"); } else if (item.getFieldName().equals("si_id")) { si.setId(Integer.parseInt(item.getString("UTF-8"))); } else if (item.getFieldName().equals("si_name")) { si.setName(item.getString("UTF-8")); } else if (item.getFieldName().equals("si_description")) { si.setDescription(item.getString("UTF-8")); } else if (item.getFieldName().equals("si_layer")) { si.setLayer(Integer.parseInt(item.getString("UTF-8"))); } else if (item.getFieldName().equals("si_opacity")) { si.setOpacity(Float.parseFloat(item.getString("UTF-8"))); } else if (item.getFieldName().equals("si_expr_x")) { si.setExprX(item.getString("UTF-8")); } else if (item.getFieldName().equals("si_expr_y")) { si.setExprY(item.getString("UTF-8")); } else if (item.getFieldName().equals("si_active")) { si.setActive(true); } else if (item.getFieldName().equals("si_users")) { si.getUsers().add(item.getString("UTF-8")); } } else { is = item.getInputStream(); si.setImageMime(Config.mimeTypes.getContentType(item.getName())); si.setImageContent(SecureStore.b64Encode(IOUtils.toByteArray(is))); is.close(); } } if (action.equals("imageCreate")) { int id = StampImageDAO.create(si); // Activity log UserActivity.log(session.getUserID(), "ADMIN_STAMP_IMAGE_CREATE", Integer.toString(id), si.toString()); imageList(session, request, response); } else if (action.equals("imageEdit")) { StampImageDAO.update(si); // Activity log UserActivity.log(session.getUserID(), "ADMIN_STAMP_IMAGE_EDIT", Integer.toString(si.getId()), si.toString()); imageList(session, request, response); } else if (action.equals("imageDelete")) { StampImageDAO.delete(si.getId()); // Activity log UserActivity.log(session.getUserID(), "ADMIN_STAMP_IMAGE_DELETE", Integer.toString(si.getId()), null); imageList(session, 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 (FileUploadException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } finally { JCRUtils.logout(session); } }
From source file:es.logongas.encuestas.presentacion.controller.EncuestaController.java
@RequestMapping(value = { "/ultima.html" }) public ModelAndView ultima(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> model = new HashMap<String, Object>(); String viewName;//from w ww .ja v a2s.c om if (request.getCharacterEncoding() == null) { try { request.setCharacterEncoding("utf-8"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(EncuestaController.class.getName()).log(Level.WARNING, "no existe el juego de caracteres utf-8", ex); } } Pregunta ultimaPregunta; ultimaPregunta = getEncuestaState(request).getRespuestaEncuesta().getUltimaPregunta(); if (ultimaPregunta == null) { throw new BusinessException(new BusinessMessage(null, "La encuesta no tiene preguntas")); } viewName = "redirect:/pregunta.html?idPregunta=" + ultimaPregunta.getIdPregunta(); return new ModelAndView(viewName, model); }
From source file:com.megaeyes.web.controller.UserController.java
@ControllerDescription(description = "?", isLog = false, isCheckSession = true) @RequestMapping("/listUserByOrgan.json") public void listUserByOrganId(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException { request.setCharacterEncoding("UTF-8"); ListUserVOResponse resp = new ListUserVOResponse(); String organId = (String) request.getAttribute("organId"); try {// w w w. j a v a 2 s . c om List<TUserVO> list = userManager.listUserByOrganId(organId); resp.setUser(list); resp.setCode(ErrorCode.SUCCESS); } catch (BusinessException be) { resp.setCode(be.getCode()); resp.setMessage(be.getMessage()); } writePageNoZip(response, resp); }