Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Forwarding to the original path is pain

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic