• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dispatching requests

 
Ken Sampson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic