This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes forward to different context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "forward to different context" Watch "forward to different context" New topic
Author

forward to different context

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
I was not aware of this.
We can 'forward' request to the resources present in other context/application...
Will it work even if both applications are not on same server???


You can not use a jsp:forward between two different servler contexts. You can use a RequestDispatcher forward between two different contexts (at least on tomcat)

1: enable cross context capability in the context config file for both contextts.
2: get a reference to the other context using ServletContext.getContext("name")
3: get the RequestDispatcher for the other context using the context object from step 2
4: do the forward

All of this logic could be coded into a custom tag.


From: http://forum.java.sun.com/thread.jspa?threadID=593250&messageID=3109439
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Will it work even if both applications are not on same server???

No, you'll have to redirect.


[My Blog]
All roads lead to JavaRanch
Vikrant Pandit
Ranch Hand

Joined: Mar 27, 2006
Posts: 245
Hi Ankur,

Just be aware that you verify that this works in your production environment which usually have highly restrictive security settings. You need to watch if your application shares the app server with other applications

Just a thought !


Vikrant Pandit
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Vivek Pandey:
Hi Ankur,

Just be aware that you verify that this works in your production environment which usually have highly restrictive security settings. You need to watch if your application shares the app server with other applications

Just a thought !


Thanks Satou and Vivek.
I was also thinking that this can be a feature of tomcat or any other web/application server but we shouldn't consider this a possiblility, I mean Sun didn't mean to provide this... just thinking, not sure.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: forward to different context