List of usage examples for javax.servlet RequestDispatcher forward
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException;
From source file:com.syrup.ui.UploadConfigurationServlet.java
/** * /* ww w . j a v a 2 s . c o m*/ * * @param req * basic request * @param resp * basic resp * @throws ServletException * basic * @throws IOException * basic */ @SuppressWarnings("unchecked") public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { // Create a new file upload handler DiskFileUpload upload = new DiskFileUpload(); // Parse the request List<FileItem> items = upload.parseRequest(req); Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { byte[] data = item.get(); // Hmm...parse images? Util.saveSuccessMessage("Service definitions uploaded.", req); } } } catch (Exception e) { Util.saveErrorMessage("Unable to upload or parse file.", req); } RequestDispatcher dispatch = req.getRequestDispatcher("/upload.jsp"); dispatch.forward(req, resp); }
From source file:org.yestech.lib.web.HtmlWriter.java
@Override public void writeTo(Object obj, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { HttpServletRequest request = ResteasyProviderFactory.getContextData(HttpServletRequest.class); HttpServletResponse response = ResteasyProviderFactory.getContextData(HttpServletResponse.class); try {//from ww w. j a v a 2s . c o m Location location = AnnotationUtil.getAnnotation(Location.class, annotations); if (location == null || StringUtils.isBlank(location.value())) { throw new RuntimeException("A Location annotation must be supplied and value must be supplied..."); } if (obj != null) { request.setAttribute(location.modelKey(), obj); } RequestDispatcher requestDispatcher = request.getRequestDispatcher(location.value()); requestDispatcher.forward(request, response); } catch (ServletException ex) { throw new WebApplicationException(ex); } }
From source file:com.mustafaderyol.inventory.beans.LoginControlClass.java
public String doLogin(ActionEvent event) 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(); return null;//from w w w . ja v a 2 s . c om }
From source file:com.taobao.diamond.server.controller.CheckServlet.java
public void forward(HttpServletRequest request, HttpServletResponse response, String page, String basePath, String postfix) throws IOException, ServletException { RequestDispatcher requestDispatcher = request.getRequestDispatcher(basePath + page + postfix); requestDispatcher.forward(request, response); }
From source file:com.github.mike10004.stormpathacctmgr.NewPasswordFormServlet.java
/** * Handles the HTTP {@code GET} method. Gets the password reset token * parameter value from the request query string and forwards to * a JSP page for rendering.//from w w w .j a va 2 s . co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ResourceException { boolean tokenVerified = false; String token = request.getParameter(PasswordReset.PARAM_RESET_TOKEN); if (token != null && !token.isEmpty()) { checkNotNullAndNotEmpty(token, "token"); Stormpaths stormpaths = createStormpaths(); Application application = stormpaths.buildApplication(); Account account; try { account = application.verifyPasswordResetToken(token); tokenVerified = true; log.log(Level.INFO, "verified token {0} and got account {1}", new Object[] { StringUtils.abbreviate(token, 32), account.getEmail() }); request.setAttribute(ATTR_TARGET_EMAIL, account.getEmail()); } catch (ResourceException e) { log.log(Level.INFO, "verifyPasswordResetToken failed: {0}", (Object) e); } } else { log.info("'sptoken' query parameter is empty or not present"); } request.setAttribute(ATTR_TOKEN_VERIFIED, tokenVerified); RequestDispatcher dispatcher = request.getRequestDispatcher(RESET_ENTER_NEW_PASSWORD_JSP_PATH); dispatcher.forward(request, response); }
From source file:FYPManagementSystem.FileUploadHandler.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String address = ""; String option = request.getParameter("Option"); String addTitle = ""; String addContent = ""; String query = ""; String queryLastID = ""; DB objDB = new DB(); //process only if its multipart content if (option.equals("Add")) { if (ServletFileUpload.isMultipartContent(request)) { try { List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()) .parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { String name = new File(item.getName()).getName(); item.write(new File(UPLOAD_DIRECTORY + File.separator + addTitle + ".jpg")); } else if (item.isFormField()) { if (item.getFieldName().contentEquals("addTitle")) { //Check if the item in the loop is the user_id addTitle = item.getString(); //If yes store the value }//ww w . jav a 2 s .c o m if (item.getFieldName().contentEquals("addContent")) { //Check if the item in the loop is the user_id addContent = item.getString(); //If yes store the value } } } query = "insert into news (newsTitle,newsContent) values('" + Common.replaceSingleQuote(addTitle) + "','" + Common.replaceSingleQuote(addContent) + "')"; //File uploaded successfully request.setAttribute("message", "File Uploaded Successfully"); } catch (Exception ex) { request.setAttribute("message", "File Upload Failed due to " + ex); } address = "WEB-INF/AdNews.jsp"; } else { request.setAttribute("message", "Sorry this Servlet only handles file upload request"); } } objDB.connect(); objDB.query(query); objDB.close(); RequestDispatcher dispatcher = request.getRequestDispatcher(address); dispatcher.forward(request, response); }
From source file:jeeves.config.springutil.JeevesAccessDeniedHandler.java
@Override public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { if (!response.isCommitted()) { if (matcher != null && matcher.matches(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage()); }/*from w w w. ja va2 s . c o m*/ if (_errorPage != null) { request.setAttribute(WebAttributes.ACCESS_DENIED_403, accessDeniedException); response.setStatus(HttpServletResponse.SC_FORBIDDEN); final String referer = _escaper.escape(request.getRequestURI()); RequestDispatcher dispatcher = request.getRequestDispatcher(_errorPage + "?referer=" + referer); dispatcher.forward(request, response); } else { response.sendError(HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage()); } } }
From source file:Controller.UpLoadFile.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, Exception { response.setContentType("text/html;charset=UTF-8"); boolean isMultipart = ServletFileUpload.isMultipartContent(request); // process only if its multipart content if (isMultipart) { // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request List<FileItem> multiparts = upload.parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { String name = new File(item.getName()).getName(); item.write(new File(UPLOAD_DIRECTORY + File.separator + name)); }/*from w ww . ja v a2 s.c o m*/ } } RequestDispatcher rd = request.getRequestDispatcher("loadimage.jsp"); rd.forward(request, response); }
From source file:org.apache.sling.dynamicinclude.SyntheticResourceFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; final String resourceType = getResourceTypeFromSuffix(slingRequest); final Configuration config = configurationWhiteboard.getConfiguration(slingRequest, resourceType); if (config == null || !config.hasIncludeSelector(slingRequest) || !ResourceUtil.isSyntheticResource(slingRequest.getResource())) { chain.doFilter(request, response); return;//from w w w .j a va2 s . co m } final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setForceResourceType(resourceType); final RequestDispatcher dispatcher = slingRequest.getRequestDispatcher(slingRequest.getResource(), options); dispatcher.forward(request, response); }
From source file:com.gunjan.businessLayer.dictServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . ja v a2 s . com*/ * * @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 queryWord = request.getParameter("word").trim(); // System.out.println("queryword----------------" + queryWord); // DBConnection conn = DBConnection.getConnection(); // System.out.println("conn ------------------------" + conn); // ArrayList<Definition> wordDefinitions = conn.getDefinition(queryWord); // if (wordDefinitions != null) { // String definitions = wordDefinitions.stream().map(d -> "<br>" + d).collect(Collectors.joining()); // request.setAttribute("definitions", definitions); // } String JSONObject = getJSONObjectForWord(queryWord); request.getSession().setAttribute("JSONObject", JSONObject); RequestDispatcher dispatch = request.getRequestDispatcher("getJSON.jsp"); dispatch.forward(request, response); }