Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

confused with getRequestDispatcher()

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • 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: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • 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
 
bacon. tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic