*
The moose likes Servlets and the fly likes dispatching requests Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "dispatching requests" Watch "dispatching requests" New topic
Author

dispatching requests

Ken Sampson
Ranch Hand

Joined: Sep 26, 2007
Posts: 45
Hello,

I have 2 servlets called TestServlet1 and TestServlet2.
In the first servlet, I write either of the following statements that would forward the page to TestServlet2.

RequestDispatcher dispatch = request.getRequestDiaspatcher("TestServlet2");

and

RequestDispatcher dispatch = request.getRequestDiaspatcher("/TestServlet2");

Could you please tell me if there is any difference between the above statements. Does that slash ("/") make any difference to anything?


Ken Sampson
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

A path beginning with "/" is relative to the application context, whereas a path not beginning with "/" is relative to the current request.

Application : /myapp
Request : /myapp/registerUser
If you forward to "/home", the request will map to "/myapp/home". If you forward to "home", the request will map to "myapp/registerUser/home".


[My Blog]
All roads lead to JavaRanch
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: dispatching requests
 
Similar Threads
Jsp under WEB-INF
fill and anchor
What is the difference between requestdispatcher and sendredirect?
Call servlet from java class and redirect to jsp page
ServletRequest RequestDispatcher