You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Saeed, Rada" <ra...@eds.com> on 2006/08/15 13:54:09 UTC

Forwards between webapps

Forwards between webapps are not supported, cuz both have different
contexts, this's what I got from running this :
<forward name="portal" path="/portal/main.do" redirect="true"
contextRelative="false" />
Is there any other way to achieve this forward between different web
applications ?





RE: Re: Forwards between webapps

Posted by "Mulligan, Scott H" <sc...@eds.com>.
I worked on a project a couple of years ago where I had the need to
forward between different web apps. Thanks to Craig McClanahan's advise
I was able to extend the RequestProcessor to do this. This was done in
Struts 1.1. Basically I set up specific forward name prefixes to
indicate when to switch web applications. When the request dispatcher
identifies one of these special prefixes it gets the context of the web
app and forwards the request. I have attached some sample code.
FYI...Craig warned me that some app servers have a switch that prohibits
or allows context sharing, but I did not have this problem in WebSphere.

    /**
     * Forward or redirect to the specified destination, by the
specified
     * mechanism.  This method uses a ForwardConfig object instead of an
     * ActionForward.
     *
     * @param request The servlet request we are processing
     * @param response The servlet response we are creating
     * @param forward The ForwardConfig controlling where we go next
     *
     * @exception IOException if an input/output error occurs
     * @exception ServletException if a servlet exception occurs
     */
	protected void processForwardConfig(HttpServletRequest request,
                                        HttpServletResponse response,
                                        ForwardConfig forward)
                                        throws IOException,
ServletException
    {
		if (forward == null)
		{
			return;
		}
		
		/* Check to see if we need to forward between web
applications.
		 * If so, we need to override how the Struts
RequestProcessor handles this.
		 * If not, just call the standard Struts
RequestProcessor's processForwardConfig
		 * method.
		 */
		if (forward.getName().startsWith("common_"))
		{
			systemLogger.debug("Forwarding to common
backend");
			String strContext ="/webApp2/common.do";
			getServletContext().getContext
				(strContext).getRequestDispatcher
	
("/common.do").forward(request,response); 
			return;
		}
		else if (forward.getName().startsWith("channel_"))
		{
			/* The parms object contains information about
where webApp2 should
			 * return control.
			 */
			 
			Parameters	parms	=
(Parameters)request.getAttribute(FrameworkConstants.PARMS);
			String	strChannel	=
(String)parms.get(FrameworkConstants.RETURN_CHANNEL);
			String	strAction	=
(String)parms.get(FrameworkConstants.RETURN_ACTION);
			String	strMethod	=
(String)parms.get(FrameworkConstants.RETURN_METHOD);
			
	
getServletContext().getContext(strChannel).getRequestDispatcher
				(strAction + "?method=" +
strMethod).forward(request,response); 
			return;
		}
		else {
			super.processForwardConfig(request, response,
forward);
		}
	}
	
Hope this helps,

Scott Mulligan


-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Laurie Harper
Sent: Thursday, August 17, 2006 4:45 PM
To: user@struts.apache.org
Subject: Re: Forwards between webapps

Scott Van Wart wrote:
> Saeed, Rada wrote:
>> Forwards between webapps are not supported, cuz both have different 
>> contexts, this's what I got from running this :
>> <forward name="portal" path="/portal/main.do" redirect="true"
>> contextRelative="false" />
>> Is there any other way to achieve this forward between different web 
>> applications ?
>>   
> I think the class 'org.apache.struts.actions.SwitchAction' might do 
> the trick (struts-config.xml):
> 
>  <action path="/toModule" 
> type="org.apache.struts.actions.SwitchAction" />
> 
> And then in your JSP:
> 
>  <html:link page="/toModule.do?prefix=portal&page=/main.do">To
> Portal</html:link>
> 
> - Scott

SwitchAction helps for switching between Struts modules within the same
webapp, not for switching between different webapps, AFAIK. It's not
possible to *forward* from one webapp to another, but redirecting is
fine.

The OP's <forward> declaration specifies a non-context-relative
redirect, which should result in a client-side (browser) redirect to the
specified URL on the same host/port.

Saeed, what happens when you try to use that forward? How is it failing
for you? It looks like it should work to me.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Re: Forwards between webapps

Posted by David Friedman <hu...@ix.netcom.com>.
If you need to share information between contexts, I believe Tomcat (if you
use it) has a setting to make a context's data  public.  With that you could
put shared items in an application scope and do JNDI lookups of the shared
data.

Regards,
David

-----Original Message-----
From: Saeed, Rada [mailto:rada.saeed@eds.com]
Sent: Sunday, August 20, 2006 2:49 AM
To: Struts Users Mailing List
Subject: RE: Re: Forwards between webapps


Scott,
     The <forward> failed simply cuz it refered to my context not to the
other different context I wanna redirect to.
I used the simple sendRedirect and it worked fine:
String path = "http://localhost:7008/portal/main.do";
response.sendRedirect(path);
return;

-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Laurie Harper
Sent: Thursday, August 17, 2006 11:45 PM
To: user@struts.apache.org
Subject: Re: Forwards between webapps

Scott Van Wart wrote:
> Saeed, Rada wrote:
>> Forwards between webapps are not supported, cuz both have different
>> contexts, this's what I got from running this :
>> <forward name="portal" path="/portal/main.do" redirect="true"
>> contextRelative="false" />
>> Is there any other way to achieve this forward between different web
>> applications ?
>>
> I think the class 'org.apache.struts.actions.SwitchAction' might do
> the trick (struts-config.xml):
>
>  <action path="/toModule"
> type="org.apache.struts.actions.SwitchAction" />
>
> And then in your JSP:
>
>  <html:link page="/toModule.do?prefix=portal&page=/main.do">To
> Portal</html:link>
>
> - Scott

SwitchAction helps for switching between Struts modules within the same
webapp, not for switching between different webapps, AFAIK. It's not
possible to *forward* from one webapp to another, but redirecting is
fine.

The OP's <forward> declaration specifies a non-context-relative
redirect, which should result in a client-side (browser) redirect to the
specified URL on the same host/port.

Saeed, what happens when you try to use that forward? How is it failing
for you? It looks like it should work to me.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Re: Forwards between webapps

Posted by "Saeed, Rada" <ra...@eds.com>.
Scott,
     The <forward> failed simply cuz it refered to my context not to the
other different context I wanna redirect to.
I used the simple sendRedirect and it worked fine:
String path = "http://localhost:7008/portal/main.do";
response.sendRedirect(path);
return;

-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Laurie Harper
Sent: Thursday, August 17, 2006 11:45 PM
To: user@struts.apache.org
Subject: Re: Forwards between webapps

Scott Van Wart wrote:
> Saeed, Rada wrote:
>> Forwards between webapps are not supported, cuz both have different 
>> contexts, this's what I got from running this :
>> <forward name="portal" path="/portal/main.do" redirect="true"
>> contextRelative="false" />
>> Is there any other way to achieve this forward between different web 
>> applications ?
>>   
> I think the class 'org.apache.struts.actions.SwitchAction' might do 
> the trick (struts-config.xml):
> 
>  <action path="/toModule" 
> type="org.apache.struts.actions.SwitchAction" />
> 
> And then in your JSP:
> 
>  <html:link page="/toModule.do?prefix=portal&page=/main.do">To
> Portal</html:link>
> 
> - Scott

SwitchAction helps for switching between Struts modules within the same
webapp, not for switching between different webapps, AFAIK. It's not
possible to *forward* from one webapp to another, but redirecting is
fine.

The OP's <forward> declaration specifies a non-context-relative
redirect, which should result in a client-side (browser) redirect to the
specified URL on the same host/port.

Saeed, what happens when you try to use that forward? How is it failing
for you? It looks like it should work to me.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Forwards between webapps

Posted by Laurie Harper <la...@holoweb.net>.
Scott Van Wart wrote:
> Saeed, Rada wrote:
>> Forwards between webapps are not supported, cuz both have different
>> contexts, this's what I got from running this :
>> <forward name="portal" path="/portal/main.do" redirect="true"
>> contextRelative="false" />
>> Is there any other way to achieve this forward between different web
>> applications ?
>>   
> I think the class 'org.apache.struts.actions.SwitchAction' might do the 
> trick (struts-config.xml):
> 
>  <action path="/toModule" type="org.apache.struts.actions.SwitchAction" />
> 
> And then in your JSP:
> 
>  <html:link page="/toModule.do?prefix=portal&page=/main.do">To 
> Portal</html:link>
> 
> - Scott

SwitchAction helps for switching between Struts modules within the same 
webapp, not for switching between different webapps, AFAIK. It's not 
possible to *forward* from one webapp to another, but redirecting is fine.

The OP's <forward> declaration specifies a non-context-relative 
redirect, which should result in a client-side (browser) redirect to the 
specified URL on the same host/port.

Saeed, what happens when you try to use that forward? How is it failing 
for you? It looks like it should work to me.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Forwards between webapps

Posted by Scott Van Wart <sc...@indosoft.com>.
Saeed, Rada wrote:
> Forwards between webapps are not supported, cuz both have different
> contexts, this's what I got from running this :
> <forward name="portal" path="/portal/main.do" redirect="true"
> contextRelative="false" />
> Is there any other way to achieve this forward between different web
> applications ?
>   
I think the class 'org.apache.struts.actions.SwitchAction' might do the 
trick (struts-config.xml):

  <action path="/toModule" type="org.apache.struts.actions.SwitchAction" />

And then in your JSP:

  <html:link page="/toModule.do?prefix=portal&page=/main.do">To 
Portal</html:link>

- Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org