List of usage examples for javax.servlet RequestDispatcher forward
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException;
From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.listing.AllClassGroupsListingController.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) { if (!isAuthorizedToDisplayPage(request, response, SimplePermission.EDIT_ONTOLOGY.ACTION)) { return;//from w w w . java2s.co m } VitroRequest vreq = new VitroRequest(request); VClassGroupDao dao = vreq.getUnfilteredWebappDaoFactory().getVClassGroupDao(); List<VClassGroup> groups = dao.getPublicGroupsWithVClasses(); // uses an unfiltered dao so will see all classes List<String> results = new ArrayList<String>(); results.add("XX"); results.add("Group"); results.add("display rank"); results.add(""); results.add("XX"); if (groups != null) { for (VClassGroup vcg : groups) { results.add("XX"); String publicName = vcg.getPublicName(); if (StringUtils.isBlank(publicName)) { publicName = "(unnamed group)"; } try { results.add("<a href=\"./editForm?uri=" + URLEncoder.encode(vcg.getURI(), "UTF-8") + "&controller=Classgroup\">" + publicName + "</a>"); } catch (Exception e) { results.add(publicName); } Integer t; results.add(((t = Integer.valueOf(vcg.getDisplayRank())) != -1) ? t.toString() : ""); results.add(""); // VClassGroup doesn't yet supprt getModTime() results.add("XX"); List<VClass> classList = vcg.getVitroClassList(); if (classList != null && classList.size() > 0) { results.add("+"); results.add("XX"); results.add("Class"); results.add("example"); results.add("description"); results.add("@@entities"); Iterator<VClass> classIt = classList.iterator(); while (classIt.hasNext()) { VClass vcw = classIt.next(); results.add("XX"); if (vcw.getName() != null && vcw.getURI() != null) { try { results.add("<a href=\"vclassEdit?uri=" + URLEncoder.encode(vcw.getURI(), "UTF-8") + "\">" + vcw.getName() + "</a>"); } catch (Exception e) { results.add(vcw.getName()); } } else { results.add(""); } String exampleStr = (vcw.getExample() == null) ? "" : vcw.getName(); results.add(exampleStr); String descriptionStr = (vcw.getDescription() == null) ? "" : vcw.getDescription(); results.add(descriptionStr); if (classIt.hasNext()) results.add("@@entities"); } } } request.setAttribute("results", results); } request.setAttribute("columncount", new Integer(5)); request.setAttribute("suppressquery", "true"); request.setAttribute("title", "Class Groups"); request.setAttribute("bodyJsp", Controllers.HORIZONTAL_JSP); request.setAttribute("horizontalJspAddButtonUrl", Controllers.RETRY_URL); request.setAttribute("horizontalJspAddButtonText", "Add new class group"); request.setAttribute("horizontalJspAddButtonControllerParam", "Classgroup"); RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); try { rd.forward(request, response); } catch (Throwable t) { t.printStackTrace(); } }
From source file:edu.lternet.pasta.portal.ReserveIdentifierServlet.java
/** * The doPost method of the servlet. <br> * // w w w . j av a 2 s . c o m * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession httpSession = request.getSession(); String uid = (String) httpSession.getAttribute("uid"); if (uid == null || uid.isEmpty()) uid = "public"; String scope = request.getParameter("scope"); String numberStr = request.getParameter("numberOfIdentifiers"); int numberOfIdentifiers = Integer.parseInt(numberStr); String message = null; String type = "info"; if (uid.equals("public")) { message = LOGIN_WARNING; type = "warning"; } else { try { DataPackageManagerClient dpmc = new DataPackageManagerClient(uid); StringBuilder sb = new StringBuilder(""); for (int i = 1; i <= numberOfIdentifiers; i++) { String identifier = dpmc.createReservation(scope); sb.append(String.format("<code>%s.%s</code>", scope, identifier)); if (i < numberOfIdentifiers) { sb.append(", "); Thread.sleep(200); } } String identifiersList = sb.toString(); if (numberOfIdentifiers == 1) { message = String.format("The following identifier has been reserved for user %s: %s", uid, identifiersList); } else { message = String.format("The following %d identifiers have been reserved for user %s: %s", numberOfIdentifiers, uid, identifiersList); } } catch (Exception e) { handleDataPortalError(logger, e); } } request.setAttribute("reservationMessage", message); request.setAttribute("type", type); RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward); requestDispatcher.forward(request, response); }
From source file:edu.lternet.pasta.portal.ScopeBrowseServlet.java
/** * The doPost method of the servlet. <br> * //from ww w . ja v a 2 s . c o m * This method is called when a form has its tag value method equals to post. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession httpSession = request.getSession(); String uid = (String) httpSession.getAttribute("uid"); if (uid == null || uid.isEmpty()) uid = "public"; String text = null; String html = null; Integer count = 0; try { DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid); text = dpmClient.listDataPackageScopes(); StrTokenizer tokens = new StrTokenizer(text); html = "<ol>\n"; ArrayList<String> arrayList = new ArrayList<String>(); // Add scope values to a sorted set while (tokens.hasNext()) { String token = tokens.nextToken(); arrayList.add(token); count++; } // Output sorted set of scope values for (String scope : arrayList) { html += "<li><a class=\"searchsubcat\" href=\"./identifierbrowse?scope=" + scope + "\">" + scope + "</a></li>\n"; } html += "</ol>\n"; } catch (Exception e) { handleDataPortalError(logger, e); } request.setAttribute("browsemessage", browseMessage); request.setAttribute("html", html); request.setAttribute("count", count.toString()); RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward); requestDispatcher.forward(request, response); }
From source file:com.arcadian.loginservlet.StudentAssignmentServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { assignmentFoldetService = new AssignmentFolderService(); HttpSession session = request.getSession(); username = (String) session.getAttribute("username"); ArrayList<AssignmentNoticeBean> alstAssignmentNotice = assignmentFoldetService .fetchAssignmentNotice(username); request.setAttribute("alstAssignmentNotice", alstAssignmentNotice); RequestDispatcher dispatcher = request.getRequestDispatcher("dashboard/assignmentfolder.jsp"); dispatcher.forward(request, response); }//from ww w . ja v a 2 s .c o m }
From source file:com.bigbang.iowservices.beans.LoginController.java
/** * * Redirects the login request directly to spring security check. Leave this * method as it is to properly support spring security. * * @return// w w w .j a va 2s. c o m * @throws ServletException * @throws IOException */ public String doLogin() throws ServletException, IOException { ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); RequestDispatcher dispatcher = ((ServletRequest) context.getRequest()) .getRequestDispatcher("/j_spring_security_check"); dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse()); FacesContext.getCurrentInstance().responseComplete(); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null) { user = userFacade.getUserInfo(auth.getName()); } System.out.println("user+++ " + user.getUserInformation().getFirstName()); return "protected"; }
From source file:eu.impact_project.wsclient.WSDLinfo.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); String wsdlURL = null;//from w ww . j a v a 2 s .c o m if (request.getParameter("wsId") != null) { wsdlURL = request.getParameter("wsId"); } else { // get WSDL file wsdlURL = request.getParameter("wsdlURL"); logger.trace("Importing WSDL from URL " + wsdlURL); } // pass the WS name to interface.jsp String wsName = null; if (request.getParameter("wsName") != null) { wsName = request.getParameter("wsName"); session.setAttribute("wsName", wsName); } logger.info("URL WSDL: " + wsdlURL); SoapService serviceObject = new SoapService(wsdlURL); // transfer values to JSP through session and request request.setAttribute("round1", "round1"); //session.setAttribute("endpointURL", endpointURL); session.setAttribute("wsdlURL", wsdlURL); //session.setAttribute("wsdlInterface", wsdlInterface); session.setAttribute("serviceObject", serviceObject); //session.setAttribute("soapOperations", soapOperations); logger.info("WSDL STRING: " + serviceObject.toString()); // get back to JSP RequestDispatcher rd = getServletContext().getRequestDispatcher("/interface.jsp"); rd.forward(request, response); }
From source file:eu.impact_project.wsclient.WSDLinfo.java
/** * Uses the passed WSDL URL to analyze the WSDL for operations and * documentation. Retrieves empty SOAP messages for the operations using * SOAP UI libraries. Passes the information further to the displaying JSP. *///w w w.j a v a2s . c o m @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); String wsdlURL = null; if (request.getParameter("wsId") != null) { wsdlURL = request.getParameter("wsId"); } else { // get WSDL file wsdlURL = request.getParameter("wsdlURL"); logger.trace("Importing WSDL from URL " + wsdlURL); } // pass the WS name to interface.jsp String wsName = null; if (request.getParameter("wsName") != null) { wsName = request.getParameter("wsName"); session.setAttribute("wsName", wsName); } logger.info("URL WSDL: " + wsdlURL); SoapService serviceObject = new SoapService(wsdlURL); // transfer values to JSP through session and request request.setAttribute("round1", "round1"); //session.setAttribute("endpointURL", endpointURL); session.setAttribute("wsdlURL", wsdlURL); //session.setAttribute("wsdlInterface", wsdlInterface); session.setAttribute("serviceObject", serviceObject); //session.setAttribute("soapOperations", soapOperations); // get back to JSP RequestDispatcher rd = getServletContext().getRequestDispatcher("/interface.jsp"); rd.forward(request, response); }
From source file:com.squid.kraken.v4.auth.ChangePasswordServlet.java
/** * Display the input screen.//from w ww .j av a 2 s .c o m * * @param request * @param response * @throws ServletException * @throws IOException */ private void show(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // execute the login request try { User user = getUser(request); request.setAttribute("user", user); request.setAttribute("access_token", request.getParameter("access_token")); } catch (ServerUnavailableException e1) { logger.error(e1.getLocalizedMessage()); request.setAttribute(KRAKEN_UNAVAILABLE, Boolean.TRUE); } catch (URISyntaxException e) { logger.error(e.getLocalizedMessage()); request.setAttribute(ERROR, Boolean.TRUE); } catch (ServiceException e) { WebServicesException wsException = e.getWsException(); String error; if (wsException == null) { error = AN_ERROR_OCCURRED; } else { error = wsException.getError(); } logger.error(error); request.setAttribute(ERROR, error); } catch (SSORedirectException e) { response.sendRedirect(e.getRedirectURL()); } RequestDispatcher rd = getServletContext().getRequestDispatcher("/password.jsp"); rd.forward(request, response); }
From source file:com.ci6225.marketzone.servlet.seller.AddProductServlet.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response)/*from ww w .ja va 2 s.co m*/ */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = null; String description = null; String unitPrice = null; String quantity = null; FileItem imageItem = null; // constructs the folder where uploaded file will be stored //String uploadFolder = getServletContext().getRealPath("") + "/productImages"; // Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(5000 * 1024); factory.setRepository(new File(System.getProperty("java.io.tmpdir"))); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); upload.setSizeMax(5000 * 1024); try { // Parse the request List<FileItem> items = upload.parseRequest(request); Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { if (item.getFieldName().equals("productImage") && !item.getString().equals("")) { imageItem = item; } System.out.println(item.getFieldName()); } else { System.out.println(item.getFieldName() + " " + item.getString()); if (item.getFieldName().equals("name")) { name = item.getString(); } else if (item.getFieldName().equals("description")) { description = item.getString(); } else if (item.getFieldName().equals("unitPrice")) { unitPrice = item.getString(); } else if (item.getFieldName().equals("quantity")) { quantity = item.getString(); } } } } catch (FileUploadException ex) { System.out.println(ex); ex.printStackTrace(); response.sendRedirect("./addProduct"); } catch (Exception ex) { System.out.println(ex); ex.printStackTrace(); response.sendRedirect("./addProduct"); } FormValidation validation = new FormValidation(); List<String> messageList = new ArrayList<String>(); if (!validation.validateAddProduct(name, description, quantity, unitPrice, imageItem)) { messageList.addAll(validation.getErrorMessages()); request.setAttribute("errorMessage", messageList); request.setAttribute("name", name); request.setAttribute("description", description); request.setAttribute("quantity", quantity); request.setAttribute("unitPrice", unitPrice); RequestDispatcher rd = request.getRequestDispatcher("./addProduct"); rd.forward(request, response); } try { User user = (User) request.getSession().getAttribute("user"); productBean.addProduct(name, description, user.getUserId(), Integer.parseInt(quantity), Float.parseFloat(unitPrice), imageItem); messageList.add("Product Added Successfully."); request.setAttribute("successMessage", messageList); RequestDispatcher rd = request.getRequestDispatcher("./ViewProductList"); rd.forward(request, response); } catch (Exception e) { e.printStackTrace(); response.sendRedirect("./addProduct"); } }
From source file:com.arcadian.loginservlet.LecturesServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { lecturesService = new LecturesService(); HttpSession session = request.getSession(); username = (String) session.getAttribute("username"); ArrayList alstClassName = lecturesService.getUserClass(username); request.setAttribute("alstClassName", alstClassName); ArrayList<LecturesBean> alstLectures = lecturesService.fetchlectures(username); request.setAttribute("alstLectures", alstLectures); RequestDispatcher dispatcher = request.getRequestDispatcher("dashboard/lectures.jsp"); dispatcher.forward(request, response); }// w w w.j a va 2 s . c om }