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
rkjhaver
Greenhorn
Joined: Jan 08, 2001
Posts: 4
posted
0
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
Frank Carver
Sheriff
Joined: Jan 07, 1999
Posts: 6913
posted
0
"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.
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
Joined: Jul 10, 2000
Posts: 50
posted
0
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 ------------------
Karn Sadyapongse
Greenhorn
Joined: Jan 09, 2006
Posts: 13
posted
0
why it doesn't work for my project ? it's still show tomcat errors
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)
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
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.
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.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.