• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

SendRedirect - RequestDispatcher

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
I have got this fundamental doubt. We know the basic difference between sendRedirect and RequestDispatcher. Is there any difference in regard to what URL these entities can access. I heard that sendRedirect can access an URL outside the existing web-app. But, requestdispatcher cannot do that.

How far is this true?

Thanx in advance!
Srini
 
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes that is correct.
sendRedirect() can use absolute URLs or relative ones. If relatives are not able to converted into absolute ones by container, it throws IllegalStateExcetpion.
req dispatcher is used to forward or include requests within a given servlet context.
You can obtain request dispatcher(rd) either from servlet context or servlet request.
If you obtain rd from servlet context you have to give path starting from "\"(root context)
If you obtain rd from servlet request you can give either strating from context root path (i call it as absolute) or relative path.
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is possible for the requestDispatcher to access a resource of another
web application , provided you can get the context of that web application

Assume there are 2 web applications

In webapplication 1 you can use
ServletContext ctx = his.getServletContext().getContext(uripath);
where uripath points to a resource in web application 2

With the context reference obtained , we can wrap the resource using the getRequestDispatcher() method of the context.

Reference:
public ServletContext getContext(java.lang.String uripath)

which says

"This method allows servlets to gain access to the context for various parts of the server, and as needed obtain RequestDispatcher objects from the context. The given path must be begin with "/", is interpreted relative to the server's document root and is matched against the context roots of other web applications hosted on this container"


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

Though you can get context of another application using getContext() method. It usually return null. It is also stated in the spec that this method can return null for security reasons !!!

Do you have any working example ? I tried it on tomcat, but not successful.

Thanks
 
This looks like a job for .... legal tender! It says so right in this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic