Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Session expire and back button in jsp and servlet .
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vikas pandey
Session expire and back button in jsp and servlet .
3 Answer(s)      2 years and 4 months ago
Posted in : JSP-Servlet


Hii Sir, I have to make a login and logout page with sessions .Now i have to invalidate

the session after a certain interval of time and after clicking logout button.Means that

after session expiry time and logout action no one can access previous pages by clicking

back button of browser without again logging.

Plz sir give me the full working code of this .It is the starting need of my project.

Thank you Sir.


Advertisement
View Answers

August 28, 2012 at 3:53 PM


Use session.invalidate() method to close the session.Here is an example.

1)login.jsp:

<html>

<head>

<title>User Login</title>
</head>
<br>
<body Bgcolor ="#0099cc"><hr><hr>

<form method="POST" action="action.jsp">
<p><b>UserName:</b> <input type="text" name="UserName" size="10"></p>
<p><b>Password:</b>   <input type="Password" name="Password" size="10"></p>
<p><input type="submit" value="Submit" name="submit"><input type=
"reset" value="Reset" name="reset"></p><hr><hr>
</form>

</body>

</html>

2)action.jsp:

<%@page import="java.util.*" %>
<script>
function go() {
window.location.replace("logout.jsp",'window','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
self.close()
}
</script>
<%String str = request.getParameter("UserName");
session.setAttribute("UserName", request.getParameter("UserName"));%>
Welcome to <%= session.getAttribute( "UserName" ) %>
<% if (session.getAttribute("UserName").equals("")){%>
<a href="login.jsp"><b>Login </b></a>
<%}
else{%>
<a href="javascript:go()"><b>Logout</b></a>
<%}
%>

3)logout.jsp:

<%session.invalidate();%>
You have logged out. Please
<a href="a.jsp"><b>Login</b></a>


August 28, 2012 at 4:10 PM


Thank you very much for your quick response. But Sir According to my need the session should be expired automatically after certain time.



April 8, 2013 at 9:59 AM


brother u have to change session time out in web.xml file..according to ur needs



Related Tutorials/Questions & Answers:
Session expire and back button in jsp and servlet .
Session expire and back button in jsp and servlet .  Hii Sir... previous pages by clicking back button of browser without again logging. Plz... to invalidate the session after a certain interval of time and after clicking logout
how to prevent from navigating Back after logout or session expire in jsp
how to prevent from navigating Back after logout or session expire in jsp  Hii Sir, I am making a web app in which after logout one can go to back pages from the browsers back button which i dont want in my app. Plz
Advertisements
Session Expire
Session Expire  Hello... i am new in JSP. i use in session.setAttribute and .getAttribute.But when i click on the sign out button i shows that the user is sign out but when i click on back button(chrom back button) it is again
session cookies expire - PHP
session cookies expire  when do a session cookies expire in PHP
how to disable back button of a browser after logging in? - JSP-Servlet
how to disable back button of a browser after logging in?  how to disable back button of a browser after logging in?  where is the source code
JSP Back Button
JSP Back Button          Jsp Back Button enables the user back... illustrate an example from 'JSP Back Button'. To understand the example we have used
Back button
Back button  how to redirect to a home page when a back button is pressed in jsp instead of displaying the previous page
How to disable browser back after logout - JSP-Servlet
How to disable browser back after logout  Dear All I created JSP... problem is, when i am clicking browser back button i can see my old visited pages data. I dont want to see my old visited pages after logout or expire the session
jsp - session - JSP-Servlet
JSP - Session  How to manage session in JSP
How to disable browser back and forward button after logout [in struts2 or jsp]
How to disable browser back and forward button after logout [in struts2 or jsp]  How to disable browser back and forward button after logout... click the back button of the browser more than one time
session.timeout and notification before session expire in java
session.timeout and notification before session expire in java  Hi... notification page when the session expires; but I want this to happen without user...; session timeout is 30 min; I would want the page to automatically forward to another
servlet session - JSP-Servlet
servlet session  how can i restrict number of users by 10 using... the counter if new user logs on and decrement if session times out or user  Hi... on and decrement if session times out or user log offs.Thanks
forwarding request to a jsp when user clicks on back button in ie
forwarding request to a jsp when user clicks on back button in ie  Hi... of the application, We should not allow the customer to go back to the previous page. Can we forward request to a jsp page whenever user clicks on back button
Browser's back button
Browser's back button  how to redirect to a home page when browser's back button is pressed in jsp instead of displaying the previous page
Enable Browser's back button
Enable Browser's back button  how to redirect to a home page when browser's back button is pressed in jsp instead of displaying the previous page
Browser's back button
Browser's back button  how to redirect to a home page when browser's back button is pressed in jsp instead of displaying the previous page
JSP - Update displayed content & session variables when user clicks on a button - JSP-Servlet
JSP - Update displayed content & session variables when user clicks on a button  Hi, I'm trying to setup a form in which the user can click... JSP to do some internal check and then increment the value of a number
servlet session - JSP-Servlet
servlet session  hi, im working on a real estate web site.....n... login servlet fromabout us page now i want the servlet to redirect me... that called the servlet: like in JS we can call a previous page
JSP - Update displayed content & session variables when user clicks on a button - JSP-Servlet
JSP - Update displayed content & session variables when user clicks... JSP to do some internal check and then increment the value of a number... combination of JSP and javascript would work since my knowledge base is in Java. Here
Session removing - JSP-Servlet
Session removing  Hi, I am destroying session by using session.invalidate() in JSP but I am not able to destroy it completely can anyone help me... has been in session using session. setAttribute() but at log off I am using
Session Timeour - JSP-Servlet
Session Timeour  Hi, How to create a session timeout page in JSP? Session timeout should happen after 15 mins of idle instance. Thanks ... the following link: http://www.roseindia.net/jsp/jsp-session-parameter
session concept - JSP-Servlet
session concept  Hello friends, How can we track unexpectedly closing a window when a jsp project running with session concept. And this tracking should update the log in status in data base
get a session object - JSP-Servlet
get a session object  how to do in a table when i click on a radio button i should get the id value which is in the same row and store it in the session this is in jsp when in the servlet if i call a get session i have to get
navigation item back button
navigation item back button  I wants to add a navigationBar on the top of my UIWebView also a navigation item "back button". can anyone please explain how the back and refresh button works
Session concept - JSP-Servlet
Session concept  Hai friends, I am doing a jsp project with session concept. If one person is not accessing his logged window for more than 10 minutes it gets automatically log out.Anybody explain me the reason
back button issue - Java Beginners
back button issue  Hello, I have a site that asks for user... pushs the back button of the explorator he can entry in the page of first user... of problem there is two solutions 1- you can disable the back button
session tracking - JSP-Servlet
session tracking  hi, i m working on a real estate web site....which i have to submit as final year project. im having problem regarding session... site how do i track his session activities....how to my pages will display his
session - JSP-Servlet
session  please send me an example code for session tracking using... that the Web server can't easily remember previous transactions.In session tracking.... There are four types of Session Tracking 1.Session 2.Cookies 3.Url-rewriting
PushViewController back button
PushViewController back button  How can i hide the back button... it always show back button.   In your ViewDidLoad method just hide the navigation back button as given in the code. navigationItem.hidesBackButton = YES
uinavigationcontroller back button action
uinavigationcontroller back button action  Hi, Tell me how to back... will display the back view on click of a button in my iPhone and iPad based application. Give me any code for uinavigationcontroller back button action method. Thanks
session maintainence - JSP-Servlet
session maintainence  if the logout link is clicked in the main page.... login application in jsp function validateForm(theForm...; } Login Application in JSP
 

 

 

DMCA.com