• 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

Redirection after session Timeout.

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on a project on JSP. I am actually working on a normal catalogue display site wherein i am gettin the details of the products from the database and putting them in sessions.

My problem is when the session expires after 30 minutes i.e. in Tomcat, I want the user to be redirected to the main page of the site since the session had expired. At present I have an error page which just displays the message of the error . So it displays null. But the user wouldn't understand that. So I just want to know what do i need to do inorder to redirect the user to the main page of the site instead of displaying him the errorpage.
Thanx in advance,
Amit
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whenever user refresh the page after 30Mins.
the session is expired it will give some by default which user cant understand.
before loading the page u check the session value.whether the value is null or not. if it is null redirect the page which will give user define message saying than u r no longer user....
please relogin again..
hope it will work fine.
rajesh kumar jhaver
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"rkjhaver",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.
Thanks.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try checking for the Session-I value before every user request. I f null is returned then redirect the user to your page of wish...
hope this helps
sagar
 
Amit Punjwani
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
thanx for u're replies.
but see i am using beans with session scope to store my data at the session .
so is it ok if I do somethin like this
<code>
<jsp:useBean id="Perfumes" class="Perfume.Perf" scope="session"/>
<%
if(Perfumes == null) {
response.sendRedirect("http://localhost:8080/home.html");
}
%>
thanx in adv
amit
------------------
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why it doesn't work for my project ?
it's still show tomcat errors


<code>
<jsp:useBean id="Perfumes" class="Perfume.Perf" scope="session"/>

<%

if(Perfumes == null) {
response.sendRedirect("http://localhost:8080/home.html");
}
%>



Is it the right way to do like this,to sendRedirect when session was time out ?
i need help
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it's still show tomcat errors


How can we possibly answer this when you dont say what error you got?

Bill
 
Karn Sadyapongse
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm sorry ,
the error is about..NullPointerException when doGet() or doPost() in servlet try to call the bean (which is already expired)
in my case,i fixed by
insert try{
}catch(Exception e){
}
cover all processes of servlet
(when NullPointerException occured,it will be throw to catch Exception
,in catch,i put sendRedirect to first page of webapp)

is there another way to fix this problem ?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, find the code causing the null pointer exception and fix it!

Eating an exception to "make it go away" is never the right solution.
 
Karn Sadyapongse
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NullPointerException occured because the session that servlet called was already expired,
how can i check that if the session was expired,don't call them

can i ?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Check out this Link
http://www.atg.com/repositories/ContentCatalogRepository_en/manuals/ATG6.0.0/apidoc/atg/projects/b2bstore/servlet/CheckSessionExpiration.html

There is a class Check Session Expiration. By using this class we can redirect to Home Page. Try it out
wish u all the best
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An expired session should not result in a null pointer exception. I think you need to dig a little deeper.
 
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you use Listeners?
Shrinivas
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Testing for expired sessions by testing the session object itself for nullness isn't always the most reliable way to go.
This is especially true if you're using a useBean tag like this:
<jsp:useBean id="Perfumes" class="Perfume.Perf" scope="session"/>
The useBean tag will create a new session if the previous one has expired.
So, your test for an exsiting session will return true, even though it isn't the same session that the user had when they originally logged in.

I've had much better luck testing for the existence of an object bound to session. When the user logs in sucessfully, create an object ("userBean") and bind it to session. Then with each hit, check to see if that object is null (filters are nice for this).
If it is, forward or redirect to the login page.

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Side note:


Compilers don't care about coding conventions and will happily work with your code no matter what capitalization scheme you follow. Humans, on the other hand, will find it very hard to read your code if you don't follow them.

An object variable (perfumes) should start with a lower case letter.
The class's name should start with an upper case "Perfumes".
Package names should be all lower case letters.

This may sound like nitpicking but seeing this:
<jsp:useBean id="Perfumes" class="Perfume.Perf" scope="session"/>
makes me wonder if the problem your having isn't due to invalid values in the 'id' and 'class' attributes in the tag.
 
reply
    Bookmark Topic Watch Topic
  • New Topic