• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

confused with getRequestDispatcher()

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am using the getRequestDispatcher of the ServletRequest and it says that it can take relative path also.
For example for example, we have to find some resource whose location is

/webapp1/html/hello.jsp

So lets say we are requested a resource


http://localhost:8080/webapp1/servlet/ServletA

The way to obtain the RequestDispatcher would be


If we look at the URL requested, it says that ServletA is in directory servlet, so .. will mean go one directory above and then find the requested resource.
In this case /servlet can be a logical directory only, it might not exist also. So far so good.

Now lets say we change the <url-pattern> to something like

<url-pattern>
/servlet/ben/ServletA
</url-pattern>

Now it means that ServletA is existing in directory ben and this time if we give something like


It will say that, the requested resource is not found, because it is searching the requested resource in the directory /servlet/html/hello.jsp.

I wanted to ask that, in this case, should SERVLET be the directory existing on root directory or it can be logical name also, then in that case
how would the RequestDispatcher relative path should have been given. Please help.

Ben
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I wanted to ask that, in this case, should SERVLET be the directory existing on root directory or it can be logical name also,



It can be a logical name.

then in that case
how would the RequestDispatcher relative path should have been given.



I'm not perfectly sure what do you mean here but the relative path in this case, where request path is /servlet/ben/ServletA, would be ../../html/file.html
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic