• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confused with getRequestDispatcher()

 
Ben Zaidi
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
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic