Win a copy of Spark in Action this week in the Open Source Projects forum!

Rao Kodeboyina

Ranch Hand
+ Follow
since Jun 09, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rao Kodeboyina

When using the forward method of the RequestDispatcher object to pass control from a servlet called ABCServlet to another servlet named XYZServlet, the easiest is to place the class files of both ABCServlet and XYZServlet in the same directory. This way, ABCServlet can be invoked from the URL http://domain/VirtualDir/servlet/ABCServlet and XYZServlet can be called from the URL http://domain/VirtualDir/servlet/XYZServlet. Using the forward method is then straightforward. You can use the getRequestDispatcher from the ServletRequest interface passing the name of the second servlet. In ABCServlet, you can write this code:

RequestDispatcher rd = request.getRequestDispatcher("XYZServlet"); rd.forward(request, response);
You don't need to include the / character before XYZServlet. This way is easiest because you don't need to worry about the paths of both servlets at all.
The harder way would be trying to pass this String to the getRequestDispatcher of ServletRequest:

"/servlet/XYZServlet"

If you have to invoke the forward method of a RequestDispatcher object obtained from the getRequestDispatcher of the ServletContext, you need to pass "/VirtualDir/servlet/XYZServlet" as the path argument, such as:

RequestDispatcher rd = getServletContext().getRequestDispatcher("/servlet/XYZServlet");
rd.forward(request, response);To use the getNamedDispatcher method, your code would become:
RequestDispatcher rd = getServletContext().getNamedDispatcher("XYZServlet");
rd.forward(request, response);
17 years ago
Good Job, Congrats
17 years ago
Good Job, Congrats
17 years ago
Good Job, Congrats
17 years ago
Good Job, Congrats
17 years ago
Good Job, Congrats
17 years ago
Good Job, Congrats
17 years ago
Great Work, Congrats
17 years ago
Good Job, Congrats
17 years ago
Good Job, Congrats
17 years ago