• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

"No Action" ActionForward

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created an Action class which does session validation by checking to see if a "loggedIn" flag is set in the session - if it is absent, or set to false, then I want to forward to the login page. However if it is set to true then I don't want to do anything - the execute() method should just complete and control should return to the calling page. But the execute() method must return an ActionForward, and it is impossible to specify a forward name/path for this case in the struts-config.xml since the path should be the path of the page that the action is being called from, and there is no way to know this information beforehand. So I am wondering how can I (within the execute() method of the SessionValidatorAction) create an ActionForward to return which will indicate the path of the calling page ? Is there a way to create and return a "No Action" ActionForward ? Can I just return null ?

I am including the action at the top of the JSPs via

<jsp:include page="SessionValidator"/>

The action mapping I'm currently using looks like this

<action path="/SessionValidator"
type="mypkg.action.SessionValidatorAction">
<forward name="invalid"
path="Login.jsp"/>
<!-- it's here that I'd specify the path to forward to when the
session is valid, but we can't know this beforehand -->
</action>

Is this the right approach/design ? If so how can I return an ActionForward from the SessionValidatorAction's execute() method which forwards control back to the calling page ? If not then how else should I go about this ?

Thanks in advance for your feedback.

-James
 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should I just go back to doing this with a servlet instead ? Perhaps I am using a Struts Action class inappropriately.

-James
 
author
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James,
What you really want to achieve is best done outside Struts. Basically you are trying to achieve two things:
1)First, a user not logged in should be forwarded to a login page.
2)Second, prevent unauthorized users from not accessing the page.
This is best done by using J2EE security. Use j_security_check in your login page and associate the logged in user with a role. Protect the resources by associating them with that role. Add a <login-config> to web.xml so that users who are not logged in, are automatically forwarded to login page.
From your second part of the description that you want to stay in the same page when logged in - it seems you are using JSP Model 1 Architecture.
But anyway, if the above security model is implemented, you dont need any filter, RequestProcessor extension or Struts Action. Your problem is solved. In your JSP, just point the link or button or form submission always to the same JSP. If the user is not authenticated J2EE container security will forward to login page. If not you will continue to stay in the same page
Hope that helps.
Srikanth Shenoy
==============================
Author: Struts Survival Guide - Basics to Best Practices
ObjectSource Publications
http://www.objectsource.com
==============================
 
reply
    Bookmark Topic Watch Topic
  • New Topic