• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

forward() in servlets.

 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what you found, when you tried that?
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic