List of usage examples for javax.servlet RequestDispatcher forward
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException;
From source file:com.bdnc.ecommercebdnc.command.CadastraProduto.java
@Override public void execute(HttpServletRequest request, HttpServletResponse response) { boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = null; try {/*ww w . j a va2 s. c o m*/ items = (List<FileItem>) upload.parseRequest(request); Produto produto = new Produto(); produto.setFoto(items.get(0).get()); produto.setDescricao(items.get(1).getString("UTF-8")); produto.setValor(Double.parseDouble(items.get(2).getString("UTF-8"))); LojaService lojaService = new LojaService(); lojaService.salvarProduto(produto); request.getSession().setAttribute("produtos", lojaService.listarProdutos()); RequestDispatcher dispather = request.getRequestDispatcher("cadastroproduto.jsp"); dispather.forward(request, response); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:org.acegisecurity.ui.AccessDeniedHandlerImpl.java
public void handle(ServletRequest request, ServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { if (errorPage != null) { // Put exception into request scope (perhaps of use to a view) ((HttpServletRequest) request).setAttribute(ACEGI_SECURITY_ACCESS_DENIED_EXCEPTION_KEY, accessDeniedException);/* ww w . ja v a2 s . c o m*/ // Perform RequestDispatcher "forward" RequestDispatcher rd = request.getRequestDispatcher(errorPage); rd.forward(request, response); } if (!response.isCommitted()) { // Send 403 (we do this after response has been written) ((HttpServletResponse) response).sendError(HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage()); } }
From source file:CheckFilter.java
private void reject(ServletRequest request, ServletResponse response) throws IOException, ServletException { request.setAttribute("errorMsg", "Please make sure to provide a valid value for all of the text fields."); Enumeration params = request.getParameterNames(); String paramN = null;// w w w . j a v a 2s.c o m while (params.hasMoreElements()) { paramN = (String) params.nextElement(); request.setAttribute(paramN, request.getParameter(paramN)); } RequestDispatcher dispatcher = request.getRequestDispatcher("/form.jsp"); dispatcher.forward(request, response); }
From source file:com.bxf.hradmin.security.AccessDeniedHandler.java
@Override public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { request.setAttribute("defaultRedirectUrl", defaultRedirectUrl); request.setAttribute("timeToRedirect", timeToRedirect); RequestDispatcher dispatcher = request.getRequestDispatcher(errorPage); dispatcher.forward(request, response); return;/*from ww w . j a v a2s . c o m*/ }
From source file:de.highbyte_le.weberknecht.security.filters.LoginPageForwardFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (logger.isDebugEnabled()) logger.debug("doFilter() - start"); boolean forward = true; if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) { logger.error("servlet request is no HTTP servlet request"); } else {//from w ww.j a v a 2 s .co m HttpSession session = ((HttpServletRequest) request).getSession(); UserAuthentication userAuthentication = (UserAuthentication) session.getAttribute("user_auth"); if (userAuthentication != null && userAuthentication.isAuthenticated()) forward = false; } if (forward) { request.setAttribute("de.highbyte_le.weberknecht.login.status", "failed"); logger.debug("doFilter() - forward to login page"); RequestDispatcher rd = request.getRequestDispatcher(loginPage); rd.forward(request, response); } else { logger.debug("doFilter() - Continue with filter chain"); chain.doFilter(request, response); } }
From source file:com.ci6225.marketzone.servlet.seller.ViewProductListServlet.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response)/*from www . ja va 2 s . c o m*/ */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { User user = (User) request.getSession().getAttribute("user"); List<Product> productList = productBean.getProductList(user.getUserId()); request.setAttribute("productList", productList); RequestDispatcher rd = request.getRequestDispatcher("./jsp/seller/product_list.jsp"); rd.forward(request, response); } catch (Exception e) { e.printStackTrace(); response.sendRedirect("./"); } }
From source file:com.ci6225.marketzone.servlet.seller.ViewProductDetailServlet.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response)/*from ww w . j a v a2 s .com*/ */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { int productId = Integer.parseInt(request.getParameter("productId")); Product product = productBean.getProduct(productId); request.setAttribute("product", product); RequestDispatcher rd = request.getRequestDispatcher("./jsp/seller/update_product.jsp"); rd.forward(request, response); } catch (Exception e) { e.printStackTrace(); response.sendRedirect("./"); } }
From source file:br.com.suricattus.surispring.spring.security.controller.FormLoginController.java
public void login() throws IOException, ServletException { if (!StringUtils.hasText(getParameter("j_username")) || !StringUtils.hasText(getParameter("j_password"))) { addMsgErro("javax.faces.loginFailed"); return;/*from w w w . java 2 s . c o m*/ } RequestDispatcher dispatcher = getRequest().getRequestDispatcher("/j_spring_security_check"); dispatcher.forward(getRequest(), getResponse()); FacesContext.getCurrentInstance().responseComplete(); }
From source file:com.gigglinggnus.controllers.AdminClockController.java
/** * * @param request servlet request//from w ww. j a v a 2s. co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EntityManager em = (EntityManager) request.getSession().getAttribute("em"); String strTime = request.getParameter("systemTime"); LocalDateTime ldTime = LocalDateTime.parse(strTime); Instant instant = ldTime.atZone(ZoneId.systemDefault()).toInstant(); Clock clk = Clock.fixed(instant, ZoneId.systemDefault()); request.getSession().setAttribute("clock", clk); RequestDispatcher rd = request.getRequestDispatcher("/home.jsp"); rd.forward(request, response); }
From source file:com.gigglinggnus.controllers.AdminClockController.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher rd = request.getRequestDispatcher("/admin/set-clock.jsp"); rd.forward(request, response); }