This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "dispatching requests" Watch "dispatching requests" New topic

dispatching requests

Ken Sampson
Ranch Hand

Joined: Sep 26, 2007
Posts: 45

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");


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é

Joined: Nov 24, 2005
Posts: 14688

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:
subject: dispatching requests
It's not a secret anymore!