struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Will Stranathan <>
Subject Re: Action Returning to previous page
Date Thu, 20 Jan 2005 12:31:20 GMT
On Wed, 19 Jan 2005 22:16:34 -0800
  Dakota Jack <> wrote:
>> > 2) Specify a <forward /> for the Action that sends the user back 
>> > from whence they came.
>> I don't think I can do this because they may come from a number of 
>You can specify a dynamic ActionForward return in your Action class
>execute(...) method.  Not sure why this presents any difficulty at

My apologies for not reading first - yeah - use a dynamic one like 
jack said.  I would PROBABLY subclass Action with an abstract subclass 
- something like:

public ... execute(...) {
   // This overrides Action.execute()

   // Do whatever up-front checking
    // Now, call my own REAL execute method:
    forward = this.doWork(mapping, form, request, response);

    // Store the path of the forward in the user's session
    // so that on their next communication back to us,
    // the go right back to the same place

// Here's a method for your doWork() implementation to
// just return a new forward for where they were before.
// You don't HAVE to call this, of course.
protected ActionMapping getDefaultForward(mapping, request) {
   try {
     return new 
   } catch (Excetpion e) {
     // Could be an NPE (attribute doesn't exist)
     // or a ClassCastException (attribute doesn't cast to a String)
     return mapping.findForward("default");

public abstract void doWork(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception;

Do NOT just copy and paste that - I've not tried it.  But rather than 
use the Referer header, I think that's a more sensible solution.  When 
you call an action of this class, it remembers where it forwards you 
to.  Then, when you call another subclass of this, if you want it to 
send you right back where you were, your doWork() implementation will 
just return  getDefaultForward(mapping, request).


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message