Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

forward() in servlets.

 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a question suppose I am hitting a URL as given below:


http://localhost:8081/myapp/servlet/login.do

Now in this Login.do servlet I am using forward method to do that following:


I want to ask that the request dispatcher will forward on which URL?

http://localhost:8081/myapp/servlet/login.do

or
http://localhost:8081/myapp/servlet/servlet/login.do



 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer correctly to your question it's important to know what is for you

/servlet/StartCISPage and how it is related to login.do

in few words is it possible to have a look at your deployment descriptor? (web.xml file)

Thank you.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what you found, when you tried that?
 
Phani Raju
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the url starts with a "/" then it is relative to the host otherwise, it is relative to the page loaded. So the request dispatcher will forward to http://localhost:8081/servlet/StartCISPage

If the request dispatcher is created without a leading slash like "servlet/StartCISPage", then it would going to http://localhost:8081/myapp/servlet/servlet/StartCISPage
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Phani Raju wrote:
If the request dispatcher is created without a leading slash like "servlet/StartCISPage", then it would going to http://localhost:8081/myapp/servlet/servlet/StartCISPage


Yes,woith out "/", *it is realtive to the current path* . so previously it was http://localhost:8081/myapp/servlet/login.do so, when you forward without slash("/") , then it search from current path so *it is http://localhost:8081/myapp/servlet/---- your url which is not start with "/" -----*

when you forward with "/" , *it is related to the context* . so server search from context i.e, http://localhost:8081/myapp/---- your url which is start with "/" ----

hth
 
Premila Devi Dayalan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
# RequestDispatcher d = httpservletrequest.getRequestDispatcher("/servlet/CAM);
# requestDispatcher.forward(httpservletrequest,response);

If the url starts with a "/" then it is relative to the host otherwise, it is relative to the page loaded. So the request dispatcher will forward to http://localhost:8081/servlet/CAM

If the request dispatcher is created without a leading slash like "servlet/CAM", then it would going to http://localhost:8081/servlet/servlet/CAM

Am I right ? Please guide
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Premila Devi wrote:Please guide


read my post . and why cant you try it out yourself ? practical gives you much confident.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic