aspose file tools*
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 Spring in Action this week in the Spring 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: 14688
    
  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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dispatching requests