wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Forwarding to the original path is pain" Watch "Forwarding to the original path is pain" New topic
Author

Forwarding to the original path is pain

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

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

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:



Merrill
Consultant, Sima Solutions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Forwarding to the original path is pain
 
Similar Threads
forward action
Remove form fields from URL during forward
Performance question
question regarding the /*.do in STRUTS
problems with action mapping