Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Page Redirection

 
Amieya Prabhaker
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Amieya Prabhaker
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you've got the idea. Anything you put in the returnTo parameter will work as long as it's a valid URI.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic