You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mon Cab <fu...@yahoo.com> on 2005/11/24 18:52:33 UTC

Can RequestDispatcher be used in an Action class

I am trying to build a login page which will direct
the user to a different page depending on what action
they were trying to perform before they logged on.  

I was thinking of using a passing a request parameter
in the request for the login page which could be used
by a request dispatched in the LoginAction class, but
dont know how that would square with returning an
action Forward using the findForward method. 

Is there any way of doing this, Or is there a better
way of doing it using ActionMapping's?




		
__________________________________ 
Start your day with Yahoo! - Make it your home page! 
http://www.yahoo.com/r/hs

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


Re: Can RequestDispatcher be used in an Action class

Posted by Laurie Harper <la...@holoweb.net>.
Mon Cab wrote:
> Thanks Lorrie. 
> 
> I hadn't realized that one could return a null
> mapping.  More than likely I will redirect to the
> referring url using a dispatcher.  
> 
> Does that sound like the best way to redirect to the
> referring URL/URI? This url would more than likely be
> another "blaBla.do" page.  

Sounds like your best option given the requirements you've stated, yes.

> I am presuming that if I tried to generate an
> ActionMapping on the fly or use a global forward, that
> there would be more work with little added benefit.  

The only benefit really is that you could use logical view identifiers 
and thereby reduce the amount of navigation info you hard-code (as 
opposed to declaring in struts-config) but I agree, unless you had a 
very specific need, this wouldn't really be worth doing.

L.

> 
> 
> --- Laurie Harper <la...@holoweb.net> wrote:
> 
>> Mon Cab wrote:
>>> I am trying to build a login page which will
>> direct
>>> the user to a different page depending on what
>> action
>>> they were trying to perform before they logged on.
>>  
>>> I was thinking of using a passing a request
>> parameter
>>> in the request for the login page which could be
>> used
>>> by a request dispatched in the LoginAction class,
>> but
>>> dont know how that would square with returning an
>>> action Forward using the findForward method. 
>>>
>>> Is there any way of doing this, Or is there a
>> better
>>> way of doing it using ActionMapping's?
>> Assuming the request parameter you're talking about
>> is a URL to forward 
>> to, you have two options: do the redirect yourself
>> and return null from 
>> the action; or construct an action mapping 'on the
>> fly' with the 
>> appropriate URL in it.
>>
>> Which you choose depends on what you want to pass in
>> as the request 
>> parameter. If you want to be able to pass any
>> arbitrary URL, do the 
>> redirect (or forward) to that URL yourself and
>> return 'null' from you 
>> action (which tells Struts you've already taken care
>> of the response so 
>> it shouldn't try to forward to a view for you).
>>
>> You can also build am action mapping in your action
>> and return that to 
>> have Struts take care of the forward/redirect for
>> you. In that case, the 
>> request parameter could contain an action path
>> instead of an absolute 
>> URL. You could even pass in the name of a global
>> forward and look the 
>> mapping up based on that.
>>
>> If the former solution meets your needs I'd suggest
>> sticking with that. 
>> Using the latter solution you may find yourself
>> needing to jump through 
>> additional hoops as your needs evolve.
>>
>> L.
>>
>>
>>
> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> user-unsubscribe@struts.apache.org
>> For additional commands, e-mail:
>> user-help@struts.apache.org
>>
>>
> 
> 
> 
> 		
> __________________________________ 
> Yahoo! Music Unlimited 
> Access over 1 million songs. Try it free. 
> http://music.yahoo.com/unlimited/


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


Re: Can RequestDispatcher be used in an Action class

Posted by Mon Cab <fu...@yahoo.com>.
Thanks Lorrie. 

I hadn't realized that one could return a null
mapping.  More than likely I will redirect to the
referring url using a dispatcher.  

Does that sound like the best way to redirect to the
referring URL/URI? This url would more than likely be
another "blaBla.do" page.  

I am presuming that if I tried to generate an
ActionMapping on the fly or use a global forward, that
there would be more work with little added benefit.  


--- Laurie Harper <la...@holoweb.net> wrote:

> Mon Cab wrote:
> > I am trying to build a login page which will
> direct
> > the user to a different page depending on what
> action
> > they were trying to perform before they logged on.
>  
> > 
> > I was thinking of using a passing a request
> parameter
> > in the request for the login page which could be
> used
> > by a request dispatched in the LoginAction class,
> but
> > dont know how that would square with returning an
> > action Forward using the findForward method. 
> > 
> > Is there any way of doing this, Or is there a
> better
> > way of doing it using ActionMapping's?
> 
> Assuming the request parameter you're talking about
> is a URL to forward 
> to, you have two options: do the redirect yourself
> and return null from 
> the action; or construct an action mapping 'on the
> fly' with the 
> appropriate URL in it.
> 
> Which you choose depends on what you want to pass in
> as the request 
> parameter. If you want to be able to pass any
> arbitrary URL, do the 
> redirect (or forward) to that URL yourself and
> return 'null' from you 
> action (which tells Struts you've already taken care
> of the response so 
> it shouldn't try to forward to a view for you).
> 
> You can also build am action mapping in your action
> and return that to 
> have Struts take care of the forward/redirect for
> you. In that case, the 
> request parameter could contain an action path
> instead of an absolute 
> URL. You could even pass in the name of a global
> forward and look the 
> mapping up based on that.
> 
> If the former solution meets your needs I'd suggest
> sticking with that. 
> Using the latter solution you may find yourself
> needing to jump through 
> additional hoops as your needs evolve.
> 
> L.
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 



		
__________________________________ 
Yahoo! Music Unlimited 
Access over 1 million songs. Try it free. 
http://music.yahoo.com/unlimited/

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


Re: Can RequestDispatcher be used in an Action class

Posted by Laurie Harper <la...@holoweb.net>.
Mon Cab wrote:
> I am trying to build a login page which will direct
> the user to a different page depending on what action
> they were trying to perform before they logged on.  
> 
> I was thinking of using a passing a request parameter
> in the request for the login page which could be used
> by a request dispatched in the LoginAction class, but
> dont know how that would square with returning an
> action Forward using the findForward method. 
> 
> Is there any way of doing this, Or is there a better
> way of doing it using ActionMapping's?

Assuming the request parameter you're talking about is a URL to forward 
to, you have two options: do the redirect yourself and return null from 
the action; or construct an action mapping 'on the fly' with the 
appropriate URL in it.

Which you choose depends on what you want to pass in as the request 
parameter. If you want to be able to pass any arbitrary URL, do the 
redirect (or forward) to that URL yourself and return 'null' from you 
action (which tells Struts you've already taken care of the response so 
it shouldn't try to forward to a view for you).

You can also build am action mapping in your action and return that to 
have Struts take care of the forward/redirect for you. In that case, the 
request parameter could contain an action path instead of an absolute 
URL. You could even pass in the name of a global forward and look the 
mapping up based on that.

If the former solution meets your needs I'd suggest sticking with that. 
Using the latter solution you may find yourself needing to jump through 
additional hoops as your needs evolve.

L.


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