I am working with jsp web project now....
In that If some user login with their own login id and password, it shoule be redirected to their own home pages...
i have already done this..
but if some time their own home page is idle, it should be displayed as
"Your session has expired" and it should be redirected to login page...
for this i want jsp code with explanation...
After user gave logout, if user presses "back" button, it shoule not be redirected to their own page... it should be remain still in login page...
for this also i want jsp code with explanation.

7 Years
Discussion Span
Last Post by siva87

Hi siva,

For this u need to check weather session object (which u created) is null or not if it is null then u need to redirect to login page.

I am giving some example:

this is in server side code ..

HttpSession session=request.getSession(false);
//here u are geeting the user name from session
		String strname=(String) session.getAttribute("username");
//here u are checking the session object (the value which u store in session) if it is null u are redirecting..		
				RequestDispatcher rd=request.getRequestDispatcher("/Login.jsp");
				rd.forward(request, response);

Like this only u need to check in jsp also.
It can surely redirect to login page..

While u logout use must invalidate the session .
write this code in logout servlet

HttpSession session = request.getSession(false);
		RequestDispatcher rd=request.getRequestDispatcher("/Login.jsp");
		rd.forward(request, response);

It is better to use filter to check the session object otherwise u need to check the condition in every servlet it become redundancy ..

I hope this is useful for u...

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags


ya... thanks kalpana... thank you very much...
but after logging out, if i click back button, it again goes to user's home page... but session expiration worked;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.