[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1801
  • Last Modified:

Session handling through HttpSessionListener in strut application

Hi All,
 
I have a struts application running on websphere 6.1.  I would like to redirect login page when the session is destroyed because of inactivity.

I  am planning to have a session listener class that implements the HttpSessionListener interface and is registered in the web.xml configuration.

I don't see any way to simple redirect in sessionDestroyed() as request object is not available.
Can it be possible that i will throw customized exception from the sessionDestroyed() method.
 This exception would be defined as a global exception in the struts configuration xml and would map back to the login page of the application.

Any better suggestion for session handling is welcome other than above.

Thanks in advance,
Dimpal

0
dimple
Asked:
dimple
  • 2
  • 2
  • 2
1 Solution
 
objectsCommented:
you can't do that.

Instead just redirect to login page if there is no session.

0
 
Murali MurugesanFull stack Java developerCommented:
i would suggest extend the Struts action class and have ur own method like isSessionValid().. in which u check for the validity of sesion. if it fails redirect to login page.

In ur action class extend the above class and as a first statement in the execute method call the isSessionValid() method. So if session is invalid it redirects to login page without much hassle...

-Murali*
0
 
dimpleAuthor Commented:
Hi objects,
Thanks for your suggestion. I already mentioned in my original question that I don't see any way to simple redirect in sessionDestroyed() as request object is not available. Can you please give me code snap how can i redirect the loggin page from sessionDestroyed() .
Thanks,
Dimpal
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dimpleAuthor Commented:
Hi Murali,
Thanks for your suggestion. Application i am referring is already exist  There are lot of action classes and to implement session checking in action class requires major code changes.
I am rather looking for any way which requires minimal effort for session handling, preciously without code changes in existing classes. The possible way  can be either by using filter or HttpSessionListener . Can you have any other better way ?  
 
Thanks,
Dimpal
0
 
objectsCommented:
> Thanks for your suggestion. I already mentioned in my original question that I don't see any way to simple redirect in sessionDestroyed() as request object is not available. Can you please give me code snap how can i redirect the loggin page from sessionDestroyed() .

as i said above you can't. Typically there will not even be a request.
0
 
Murali MurugesanFull stack Java developerCommented:
I can think another solution using ajax if u don't want to modify ur code.
As soon as some one visit the page start a counter at the client side say for 30 minutes (default session expiry) in case u have set something below this then run the counter till that time. Once the time is reached give an ajax call to a servlet where it checks the session validity. if Session is invalid redirect to login page,probably u can show an alert to client and then redirect to the login page.

You can have this logic in a seperate jsp file and include them in all the other files. This way i hope u need not  touch other existing classes.

-Murali*
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now