Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Session Timed out Problem

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,

On leaving the IE window idle for approx. half an hour & therafter on submitting the form (JSP Page), it gives the following error msg.


When i close the window & reopen another instance of IE window - everything works fine.

I believe that the Session may be getting Timed out.

Can someone suggest me, on Session Time Out when i submit the JSP page, how to forward to a JSP Page showing that the "session has timed out" - instead of the above error code.

Or else

How to increase the expiry time limit for Sessions?

Please suggest.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best way to deal with this problem in a Struts application is to put code at the beginning of each action class that checks to see whether a specific object exists in the session or not. In most cases, you have an object such as a User object indicating that the user is signed on to the system. If you don't already have such an object, create one. Once you have an object that you know should always be in the session, check for it like this:


For more discussion on this, see this thread.

If you don't want to put this code in every action, you could create a base action that has this code and then have all your other actions extend this base action.

Also, to answer your other question: Specifying how long before a session expires can be done in your application server's admin interface or in your web.xml file.
 
Shailesh Pillai
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Merill for your reply,
I am storing the user information as follows in my Login Action class:

request.getSession(true).setAttribute("User", user);

And in the remaining Action classes when i am putting the below code, it is still giving me the same error.

[ August 27, 2006: Message edited by: Shailesh Pillai ]
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shailesh Pillai:
And in the remaining Action classes when i am putting the below code, it is still giving me the same error.

code:
------------------------------------------------------------------------

String user;user=(String)request.getSession().getAttribute("User");
if (user.equals(null))//session timed out
------------------------------------------------------------------------



Definitely you will get NullPointerException as still you are doing the same thing.

Have you gone through your code snippet? What will happen if session gets expired, then user will point to null. Calling any String method from a null string will return the same exception.

Use == operator for comparing the references as explained by Merrill not equals() method.

Naseem
[ August 27, 2006: Message edited by: Naseem Khan ]
 
Shailesh Pillai
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Naseem,
Did as you suggested
But, still getting the same exception.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us your code as well as the stack trace you're getting from the error. If you really did change it to "if (user == null)", there's no way that statement could throw a null pointer exception. Check the line number on the stack trace to see specifically which line is throwing the exception. I'm guessing it will be a different line in your code.
 
Shailesh Pillai
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Merill and Naseem,
Got it.
The problem was -
Before performing the null comparison i.e. (user==null), i had another session variable named 'StationId'-which i was storing in another String variable.
i.e. stnId=(String)request.getSession().getAttribute("StationId");

That's why it was giving null pointer exception.

I just put the 'null comparison' code before the above code. And now its working.

Thanks once again.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic