• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Forwarding to the original path is pain  RSS feed

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

Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!