This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
  • Carey Brown
  • salvin francis
  • Claude Moore

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 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:

If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
Create Edit Print & Convert PDF Using Free API with Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!