List of usage examples for javax.servlet RequestDispatcher forward
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException;
From source file:com.maya.portAuthority.googleMaps.MapsService.java
/** * Web application to determine nearest bus stop from a source location for a given route# and * direction of transit.// ww w .j a va2 s. c o m */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { //NearestStopLocator p = new NearestStopLocator(); //Inputs fom UI: String source = request.getParameter("source").replaceAll("\\s", "+"); String route = request.getParameter("route").trim(); String direction = request.getParameter("direction").trim(); try { Location c = NearestStopLocator.getSourceLocation(source); Stop stop = NearestStopLocator.process(c, route, direction); request.setAttribute("nearestStopName", stop.getStopName()); } catch (JSONException ex) { Logger.getLogger(MapsService.class.getName()).log(Level.SEVERE, null, ex); } catch (InvalidInputException ex) { Logger.getLogger(MapsService.class.getName()).log(Level.SEVERE, null, ex); } //direct to the results page RequestDispatcher view = request.getRequestDispatcher("result.jsp"); view.forward(request, response); }
From source file:cz.muni.fi.myweb1.RestaurantServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher rd = request.getRequestDispatcher("/outline.jsp"); rd.forward(request, response); }
From source file:cz.muni.fi.myweb1.registerServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w ww .j ava 2 s. c o 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 { String name = (String) request.getAttribute("username"); String password = (String) request.getAttribute("password"); Boolean employee = Boolean.parseBoolean(request.getAttribute("employee").toString()); if (myFacade.register(name, password, employee)) { request.getSession().setAttribute("username", name); RequestDispatcher rd = request.getRequestDispatcher("/outline.jsp"); rd.forward(request, response); } else { //TODO error } }
From source file:controller.product.renderUpdateProductServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Product product = new Product(); ProductDAO productDAO = new ProductDAO(); String name = request.getParameter("name"); if (productDAO.connect()) { product = productDAO.getProductByName(name); request.setAttribute("product", product); }//from ww w . j av a 2 s.co m productDAO.disconnect(); RequestDispatcher rd = request.getRequestDispatcher("adminpages/updateProduct.jsp"); rd.forward(request, response); }
From source file:controller.product.renderUpdateProductServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Product product = new Product(); ProductDAO productDAO = new ProductDAO(); String name = request.getParameter("name"); if (productDAO.connect()) { product = productDAO.getProductByName(name); request.setAttribute("product", product); }/*from ww w .j av a2 s.c o m*/ productDAO.disconnect(); RequestDispatcher rd = request.getRequestDispatcher("adminpages/updateProduct.jsp"); rd.forward(request, response); }
From source file:net.hillsdon.reviki.web.dispatching.impl.ResourceHandlerImpl.java
public View handle(final ConsumedPath path, final HttpServletRequest request, final HttpServletResponse response) throws Exception { if (!path.hasNext()) { throw new NotFoundException(); }/*from w w w . java2 s .c o m*/ StringBuilder sb = new StringBuilder("/resources"); while (path.hasNext()) { sb.append("/"); sb.append(URIUtil.encodeWithinPath(path.next())); } final String resource = sb.toString(); return new View() { public void render(final HttpServletRequest request, final HttpServletResponse response) throws Exception { RequestDispatcher requestDispatcher = request.getRequestDispatcher(resource); requestDispatcher.forward(request, response); } }; }
From source file:org.beangle.security.web.access.DefaultAccessDeniedHandler.java
public void handle(ServletRequest request, ServletResponse response, AccessDeniedException exception) throws IOException, ServletException { if (null != location) { }/* www .ja v a 2s . c om*/ if (errorPage != null) { // Put exception into request scope (perhaps of use to a view) ((HttpServletRequest) request).setAttribute(ACCESS_DENIED_EXCEPTION_KEY, exception); // 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, exception.getMessage()); } }
From source file:alpha.portal.webapp.filter.MockFilterChain.java
public void doFilter(final ServletRequest request, final ServletResponse response) throws IOException, ServletException { String uri = ((HttpServletRequest) request).getRequestURI(); final String requestContext = ((HttpServletRequest) request).getContextPath(); if (StringUtils.isNotEmpty(requestContext) && uri.startsWith(requestContext)) { uri = uri.substring(requestContext.length()); }/* www. ja va 2 s. co m*/ this.forwardURL = uri; this.log.debug("Forwarding to: " + uri); final RequestDispatcher dispatcher = request.getRequestDispatcher(uri); dispatcher.forward(request, response); }
From source file:controller.KlantController.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String forward = ""; String action = request.getParameter("action"); if (action.equalsIgnoreCase("delete")) { int idKlant = Integer.parseInt(request.getParameter("idKlant")); dao.deleteKlantById(idKlant);/*from ww w . ja v a 2s .co m*/ forward = LIST_KLANT; request.setAttribute("klanten", dao.readAlleKlanten()); } else if (action.equalsIgnoreCase("edit")) { forward = INSERT_OR_EDIT; int idKlant = Integer.parseInt(request.getParameter("idKlant")); Klant klant = dao.readKlantOpId(idKlant); request.setAttribute("klant", klant); } else if (action.equalsIgnoreCase("listKlant")) { forward = LIST_KLANT; request.setAttribute("klanten", dao.readAlleKlanten()); } else { forward = INSERT_OR_EDIT; } RequestDispatcher view = request.getRequestDispatcher(forward); view.forward(request, response); }
From source file:web.KategoriServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w . j a 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 { EntityManager em = emf.createEntityManager(); KategoriDAO dao = new KategoriDAOImpl(em); request.setAttribute("kategoris", dao.getAll()); RequestDispatcher rd = request.getRequestDispatcher("daftar_kategori.jsp"); rd.forward(request, response); }