jQuery in Action, 3rd edition
The moose likes Struts and the fly likes Forwarding to the original path is pain Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Forwarding to the original path is pain" Watch "Forwarding to the original path is pain" New topic

Forwarding to the original path is pain

Hussein Baghdadi
clojure forum advocate

Joined: Nov 08, 2003
Posts: 3479

In my Struts application, I'm trying to store the original request path if the user hasn't yet logged in.
I'm controlling access to restricted actions using a filter, this filter saves the original request path in the request scope and then forwards the request the login.jsp page.
login.jsp page stores passed path as a hidden filed, login form is submitted to login.do
login.do action (Yes, it is a Struts action) try to authenticates the user and if every thing is ok, it should forwards the user to his original path or to his inbox page.
Do you see the problem ?
Struts action's execute method has to return an ActionForwad which forwards to an already known destination in struts-config.xml
Suppose I have 30 protected pages which means 30 possible original paths so setting if-else block in the action and 30 mapping in the config file doesn't sound good (FYI, I'm not a masochist).
So, how do I do that ? (forwarding to the original path, not the masochist )
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Although in most cases it's better to use the forwards defined in the struts-config.xml file, in some cases such as the one you describe, it's better to use a dynamic forward. It is not a requirement to use mapping.findForward(). You can simply instantiate an ActionForward for a given path. Here's an example:

Consultant, Sima Solutions
I agree. Here's the link: http://aspose.com/file-tools
subject: Forwarding to the original path is pain
It's not a secret anymore!