Title: How many RequestDispatchers do I need?

If I have a Servlet that controls the access to a web site. Should I have one RequestDispactcher to handle any request, or should I have a RequestDispatcher for each request. "callingPage" is a hidden field in each html page

 RequestDispatcher pageRD = null;
   
    System.out.println("This is ControlServlet....Please reload it....");
    String prevPage = request.getParameter("callingPage");
    System.out.println("prevPage==========="+ prevPage);
    System.out.println("pathInfo==========="+ request.getPathInfo());

    if (prevPage == null) {
      System.out.println("************Calling index.jsp");
      //directPageTo(request,response, pageRD, "index.jsp");
      pageRD = this.getServletContext().
        getRequestDispatcher("/index.jsp");
      pageRD.forward(request, response);
    }
    else if (prevPage.equals("registration.html")){
      System.out.println("**********calling agreement.jsp");
      pageRD = this.getServletContext().
        getRequestDispatcher("/register/agreement.jsp");
      pageRD.forward(request, response);
    }else if (prevPage.equals("agreement.jsp")){
      System.out.println("**********in registration.html");
      if (request.getParameter("radiobutton").equals("parent")) {
        System.out.println("in parent" + request.getParameter("radiobutton"));
        pageRD = this.getServletContext().
          getRequestDispatcher("/register/register_parent.html");
        pageRD.forward(request, response);
      }

Reply via email to