List of usage examples for javax.servlet RequestDispatcher forward
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException;
From source file:com.mkmeier.quickerbooks.ProcessSquare.java
private void showForm(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { //Load Account Options Map<String, List<QbAccount>> accountLists = getAccountLists(); HttpSession session = request.getSession(true); session.setAttribute("lists", accountLists); RequestDispatcher rd = request.getRequestDispatcher("SquareProcessor.jsp"); rd.forward(request, response); }
From source file:eu.eidas.node.connector.ConnectorExceptionHandlerServlet.java
/** * Prepares exception redirection, or if no information is available to redirect, prepares the exception to be * displayed. Also, clears the current session object, if not needed. * * @return {ERROR} if there is no URL to return to, {SUCCESS} otherwise. *//* ww w . j a va 2 s. c o m*/ private void handleError(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /* Current exception. */ AbstractEIDASException exception; /* URL to redirect the citizen to. */ String errorRedirectUrl; String retVal = NodeViewNames.INTERCEPTOR_ERROR.toString(); try { // Prevent cookies from being accessed through client-side script. setHTTPOnlyHeaderToSession(false, request, response); //Set the Exception exception = (AbstractEIDASException) request.getAttribute("javax.servlet.error.exception"); prepareErrorMessage(exception, request); errorRedirectUrl = prepareSession(exception, request); request.setAttribute(NodeParameterNames.EXCEPTION.toString(), exception); retVal = NodeViewNames.ERROR.toString(); if (!StringUtils.isBlank(exception.getSamlTokenFail()) && null != errorRedirectUrl) { retVal = NodeViewNames.SUBMIT_ERROR.toString(); } else { LOG.debug("BUSINESS EXCEPTION - null redirectUrl or SAML response"); retVal = NodeViewNames.INTERCEPTOR_ERROR.toString(); } } catch (Exception e) { LOG.info("BUSINESS EXCEPTION: in exception handler: " + e, e); } //Forward to error page RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(retVal); response.setStatus(HttpServletResponse.SC_OK); dispatcher.forward(request, response); }
From source file:jetbrains.buildServer.symbols.DownloadSourcesController.java
@Nullable @Override/*from www . j a v a 2s . co m*/ protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws Exception { final String requestURI = request.getRequestURI(); if (!requestURI.matches(VALID_URL_PATTERN)) { WebUtil.notFound(request, response, "Url is invalid", null); return null; } final SUser user = myAuthHelper.getAuthenticatedUser(request, response, new Predicate<SUser>() { public boolean apply(SUser user) { return true; } }); if (user == null) return null; String restMethodUrl = requestURI.replace("/builds/id-", "/builds/id:").replace("/app/sources/", "/app/rest/"); final String contextPath = request.getContextPath(); if (restMethodUrl.startsWith(contextPath)) { restMethodUrl = restMethodUrl.substring(contextPath.length()); } RequestDispatcher dispatcher = request.getRequestDispatcher(restMethodUrl); if (dispatcher != null) { LOG.debug(String.format("Forwarding request. From %s To %s", requestURI, restMethodUrl)); dispatcher.forward(request, response); } return null; }
From source file:cust_photo_upload.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w ww . jav 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 */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); HttpSession hs = request.getSession(); try (PrintWriter out = response.getWriter()) { Login ln = (Login) hs.getAttribute("user"); String pname = ln.getUName(); String p = ""; // // creates FileItem instances which keep their content in a temporary file on disk FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); //get the list of all fields from request List<FileItem> fields = upload.parseRequest(request); // iterates the object of list Iterator<FileItem> it = fields.iterator(); //getting objects one by one while (it.hasNext()) { //assigning coming object if list to object of FileItem FileItem fileItem = it.next(); //check whether field is form field or not boolean isFormField = fileItem.isFormField(); if (isFormField) { //get the filed name String fieldName = fileItem.getFieldName(); } else { String extension; String fieldName = fileItem.getFieldName(); if (fieldName.equals("photo")) ; { //getting name of file p = new File(fileItem.getName()).getName(); //get the extension of file by diving name into substring extension = p.substring(p.indexOf(".") + 1, p.length()); ; //rename file...concate name and extension p = pname + "." + extension; try { String filePath = this.getServletContext().getRealPath("/images") + "\\"; fileItem.write(new File(filePath + p)); } catch (Exception ex) { out.println(ex.toString()); } } } } // hs.setAttribute("photo", photo); // SessionFactory sf=NewHibernateUtil.getSessionFactory(); // Session s=sf.openSession(); // Transaction t=s.beginTransaction(); // Imagedata im=new Imagedata(); // im.setIname(pname); // im.setIurl(photo); // s.save(im); // t.commit(); // RequestDispatcher rd = request.getRequestDispatcher("viewserv"); rd.forward(request, response); // response.sendRedirect("viewserv"); } catch (Exception ex) { out.println(ex.getMessage()); } }
From source file:com.mockey.ui.TwistInfoSetupServlet.java
/** * Handles the following activities for <code>TwistInfo</code> * /* ww w .j a va 2 s . c o m*/ */ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { List<TwistInfo> twistInfoList = store.getTwistInfoList(); String responseType = req.getParameter("response-type"); // If type is JSON, then respond with JSON // Otherwise, direct to JSP if (PARAMETER_KEY_RESPONSE_TYPE_VALUE_JSON.equalsIgnoreCase(responseType)) { // *********************** // BEGIN - JSON response // *********************** resp.setContentType("application/json"); PrintWriter out = resp.getWriter(); try { JSONObject jsonResponseObject = new JSONObject(); JSONObject jsonObject = null; // new JSONObject(); for (TwistInfo twistInfo : twistInfoList) { jsonObject = new JSONObject(); jsonObject.put("id", "" + twistInfo.getId()); jsonObject.put("name", twistInfo.getName()); for (PatternPair patternPair : twistInfo.getPatternPairList()) { JSONObject ppObj = new JSONObject(); ppObj.put("origination", patternPair.getOrigination()); ppObj.put("destination", patternPair.getDestination()); jsonObject.append("pattern-pair-list", ppObj); } } jsonResponseObject.put("result", jsonObject); out.println(jsonResponseObject.toString()); } catch (JSONException jsonException) { throw new ServletException(jsonException); } out.flush(); out.close(); return; // *********************** // END - JSON response // *********************** } else { req.setAttribute("twistInfoList", twistInfoList); req.setAttribute("twistInfoIdEnabled", store.getUniversalTwistInfoId()); RequestDispatcher dispatch = req.getRequestDispatcher("/twistinfo_setup.jsp"); dispatch.forward(req, resp); return; } }
From source file:controller.uploadPergunta5.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w . ja v a 2 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 */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String idLocal = (String) request.getParameter("idLocal"); String idEquacao = (String) request.getParameter("idEquacao"); String name = ""; //process only if its multipart content if (ServletFileUpload.isMultipartContent(request)) { try { List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { name = new File(item.getName()).getName(); // item.write( new File(UPLOAD_DIRECTORY + File.separator + name)); item.write(new File(AbsolutePath + File.separator + name)); } } //File uploaded successfully request.setAttribute("message", "File Uploaded Successfully"); } catch (Exception ex) { request.setAttribute("message", "File Upload Failed due to " + ex); } } else { request.setAttribute("message", "Sorry this Servlet only handles file upload request"); } RequestDispatcher view = getServletContext().getRequestDispatcher( "/novoLocalPergunta5?id=" + idLocal + "&nomeArquivo=" + name + "&idEquacao=" + idEquacao); view.forward(request, response); // request.getRequestDispatcher("/novoLocalPergunta3?id="+idLocal+"&fupload=1&nomeArquivo="+name).forward(request, response); // request.getRequestDispatcher("/novoLocalPergunta4?id="+idLocal+"&nomeArquivo="+name).forward(request, response); }
From source file:edu.lternet.pasta.portal.LoginServlet.java
/** * The doPost method of the servlet. <br> * // ww w . j a v a 2 s. com * 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 */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession httpSession = request.getSession(); String from = (String) httpSession.getAttribute("from"); String uid = request.getParameter("uid"); String password = request.getParameter("password"); String forward = null; try { new LoginClient(uid, password); httpSession.setAttribute("uid", uid); if (from == null || from.isEmpty()) { forward = "./home.jsp"; } else { forward = from; httpSession.removeAttribute("from"); } } catch (PastaAuthenticationException e) { String message = "<strong><em>Login failed</em></strong> for user <kbd class=\"nis\">" + uid + "</kbd>."; forward = "./login.jsp"; request.setAttribute("message", message); } try { TokenManager tm = new TokenManager(); logger.info(tm.getCleartextToken(uid)); logger.info(tm.getUserDistinguishedName(uid)); logger.info(tm.getTokenAuthenticationSystem(uid)); logger.info(tm.getTokenTimeToLive(uid)); ArrayList<String> groups = tm.getUserGroups(uid); for (String group : groups) { logger.info(group); } logger.info(tm.getTokenSignature(uid)); // Let's try to alter the token /* String token = tm.getToken(uid); token = Escalator.addGroup(token, "super"); tm.setToken(uid, token); logger.info(tm.getCleartextToken(uid)); */ } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (java.sql.SQLException e) { e.printStackTrace(); } RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward); requestDispatcher.forward(request, response); }
From source file:com.inkubator.sms.gateway.web.LoginController.java
public String doLogin() { System.out.println(" do login"); ExternalContext context = FacesUtil.getExternalContext(); RequestDispatcher dispatcher = ((ServletRequest) context.getRequest()) .getRequestDispatcher("/" + SMSGATEWAY.SPRING_SECURITY_CHECK); try {//w w w .j av a 2s . co m dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse()); } catch (ServletException | IOException ex) { LOGGER.error("Error", ex); } FacesUtil.setSessionAttribute(SMSGATEWAY.LOGIN_DATE, dateFormatter.getDateFullAsStringsWithActiveLocale(new Date(), new Locale(selectedLanguage))); FacesUtil.getFacesContext().responseComplete(); return null; }
From source file:controller.servlet.Upload.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w .j a v a2 s . 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 */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Obtencin de la ruta a la carpeta de ficheros. String path = this.getServletContext().getRealPath(""); path += File.separator + Path.UPLOADEDFILES_FOLDER; File directory = new File(path); if (!directory.exists()) { directory.mkdirs(); } HttpSession session = request.getSession(true); UploadedFileDaoImpl uFD = new UploadedFileDaoImpl(); // Asigancin de valores. session.setAttribute("mUF", uFD.getFiles()); session.setAttribute("serverFolderFiles", directory.listFiles()); // Redireccin. String page = "/pages/upload.jsp"; RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher(page); requestDispatcher.forward(request, response); }
From source file:controller.uploadPergunta8ArquivoAjuste.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w .ja v a 2s .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 */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String idLocal = (String) request.getParameter("idLocal"); String idModelo = (String) request.getParameter("idModelo"); String name = ""; //process only if its multipart content if (ServletFileUpload.isMultipartContent(request)) { try { List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { name = new File(item.getName()).getName(); // item.write( new File(UPLOAD_DIRECTORY + File.separator + name)); item.write(new File(AbsolutePath + File.separator + name)); } } //File uploaded successfully request.setAttribute("message", "File Uploaded Successfully"); } catch (Exception ex) { request.setAttribute("message", "File Upload Failed due to " + ex); } } else { request.setAttribute("message", "Sorry this Servlet only handles file upload request"); } RequestDispatcher view = getServletContext().getRequestDispatcher( "/novoLocalPergunta8?id=" + idLocal + "&nomeArquivoAjuste=" + name + "&idModelo=" + idModelo); view.forward(request, response); // request.getRequestDispatcher("/novoLocalPergunta3?id="+idLocal+"&fupload=1&nomeArquivo="+name).forward(request, response); // request.getRequestDispatcher("/novoLocalPergunta4?id="+idLocal+"&nomeArquivo="+name).forward(request, response); }