Session expire and back button in jsp and servlet .

Session expire and back button in jsp and 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.

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
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
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
jsp - session - JSP-Servlet
JSP - Session  How to manage session in JSP
JSP Back Button
JSP Back Button          Jsp Back Button enables the user back... The Tutorial illustrate an example from 'JSP Back Button'. To understand
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
session cookies expire - PHP
session cookies expire  when do a session cookies expire in PHP
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
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
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
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
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 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 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
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
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
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 Problem in JSP - JSP-Servlet
Session Problem in JSP  I have developed a online feedback form in JSP platform. I have created normal session in JSP page. It is running in my... then the session is not working. I have not used EJB. Please tell me how can I track session
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 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
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
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
Servlet Session Tracking - JSP-Servlet
Servlet Session Tracking  Hi I have made a main page called... to a new Servlet of name: SessionNew by URL Redirecting method, but instead fo giving..."); PrintWriter pw = res.getWriter(); pw.println("Test Session Attributes
session - JSP-Servlet
redirect the session  how i can redirect the session in any child window
session - JSP-Servlet
session  How to manage session for a particular user ..using session management?  Answer:If you get id as a integer from mlid field then userid is set in your session.RegardsAmar  Answer:If you get id
session maintainence - JSP-Servlet
session maintainence  how to enable a link only if the form in previous page is clucked  please show me your code
Session Tracking JSP - JSP-Servlet
Session Tracking JSP  Respected sir/madam, I am R.Ragavendran.. I Immediately need a coding for session tracking in JSP. Actually when... information. http://www.roseindia.net/jsp/loginstatus.shtml Thanks
arraylist with session - JSP-Servlet
arraylist with session  hi how can an arraylist stored in session.. and also how will it access?? pls give me the details with sample code..   Hi friend, Code to solve the problem : Thanks
session management - JSP-Servlet
session management  hi friends... hope u all dng fine. i am dng... think i am not using session management properly. and also in my web.xml file i said session timeout 1min. even it is also not working.wht to do :-( i will give
radio button in jsp - JSP-Servlet
radio button in jsp  hye there.how do I create radio button in jsp?Could you please gimme an example of shopping cart in jsp which have I have using a Netbean not a tomcat.What is the code for view and update in jsp?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
Download Button - JSP-Servlet
how to implement the download button so that on clicking that the mini
Radio button in JSP - JSP-Servlet
Radio button in JSP  Hi! In my page I have two radio buttons. If i select first radio button. one text field has to be displayed.... If i select second radio button. text field has to be disappeared. pls.... help me.. 
Radio button validation using jsp - JSP-Servlet
Radio button validation using jsp  I had one jsp Page and servlet. I did my validations in servlet for my jsp page which contains the radio buttons.Here,the servlet acts as controller and if there is any null(i.e., not choosen
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
session syntax for logout - JSP-Servlet
session syntax for logout  What is the syntax for writing session.../jsp/  For the security reason, every application requires login... users.No matters it devekoped using Java, Jsp or any other language!Try above
Login Authentication and session in JSP - JSP-Servlet
Login Authentication and session in JSP  Hi, I am creating an small application in JSP,in which i need to check user authentication and session on each JSP page.Also how do i make logout page. Can you help me
JSP Radio Button MySQL insert - JSP-Servlet
JSP Radio Button MySQL insert  Hi, I have an HTML form which has... with select lists. I have created a servlet to connect to MySQL database... with the code to store radio button data and checkbox data to MySQL table. For example
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
java (servlet) - JSP-Servlet
java (servlet)  how can i disable back button in brower while using servlet or JSP
How to implement session variables - JSP-Servlet
How to implement session variables  Hi, I have a servlet which gets parameter from a jsp page(x). it is stored in a variable in servlet as shown below. the servlet response is another jsp page(y). I should put the value of amp
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
How to disable browser back after logout - JSP-Servlet
How to disable browser back after logout  thanks deepak, i tried but if i am clicking back still i can see my old pages. i copied your code.... -- Rajkumar  Hi friend, Check the session is exists
get a radio button click value - JSP-Servlet
") in servlet that is used in another jsp so can i call getParameter("radio") i.e... servlet from another jsp i.e 'main.jsp', then you have to store the value of id...get a radio button click value  thanks sir for sending code ,but i
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
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
problem without session tracking - JSP-Servlet
problem without session tracking  i want to see the code in which no session tracking has done and that is yielding the problem without session.... For read more information : http://www.roseindia.net/jsp/ Thanks  

Ads