aspose file tools*
The moose likes Struts and the fly likes Struts Page Redirection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Page Redirection" Watch "Struts Page Redirection" New topic
Author

Struts Page Redirection

Amieya Prabhaker
Ranch Hand

Joined: Apr 23, 2006
Posts: 45
I have a simple question on best means to implement this using struts: (perhaps simple javascript may work?)

Say there are 3 pages A, B, C with : A having links to B & C. B having a link to C.
A -> B, C
B -> C

The route of reaching C determines the return button action in page C.
So if one reaches page C from A, the return should take back to A.
But SAME return button should take back to page B, if approached from B.

What's the best struts way to do this (without getting tempted to do a javascript thing:
<a href="javascript:history.go(-1)">GO BACK</a>
Amieya Prabhaker
Ranch Hand

Joined: Apr 23, 2006
Posts: 45
I looked at this article which describes the "Back page" struts problem.

http://www.manfred-wolff.de/struts/articles-old/HowTo-Back.html

Wonder if a brief strutsy solution for just the 3 pages above is available?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
One simple solution would be to include a "returnTo" parameter in the link that contains the URL to return to after the link. You will have to "escape" some of the charaters such as "/" so that they don't mess up the URL, but you can use the java.net.URLEncoder class for this.

Then in the Action class, simply retrieve the returnTo parameter. You can then dynamically create a forward that refers to it, and the return that forward. Example:

In the Jsp:

in the Action class:


Merrill
Consultant, Sima Solutions
Amieya Prabhaker
Ranch Hand

Joined: Apr 23, 2006
Posts: 45
Sounds like a probable solution. To break down in simple terms for better understanding:
Can Page A jsp include something like:

<html:link page='<%="myaction.do?returnTo="+URLEncoder.encode("PageA.do")%>'>Click here</html:link>

and corresponding Page B jsp include:
<html:link page='<%="myaction.do?returnTo="+URLEncoder.encode("PageB.do")%>'>Click here</html:link>

Both above are pointing to Page C, for which the back can be obtained using the returnTo parameter to return to correct A/B page?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I think you've got the idea. Anything you put in the returnTo parameter will work as long as it's a valid URI.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts Page Redirection