File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Session Logout Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Logout Problem" Watch "Session Logout Problem" New topic
Author

Session Logout Problem

vikka sharma
Greenhorn

Joined: Jan 27, 2011
Posts: 3
I have one jsp in which i enter username and password.It calls another jsp which set loginId and some other stuff in session.Now when i click on one hyperlink which is calling a servlet through javascript function , in the servlet i use this code:-

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

try{
HttpSession session = request.getSession(false);
if(session==null){
response.sendRedirect("./loginForCSR.jsp");
return;
}

RegistrationDAL registrationDAL = new RegistrationDAL();
ArrayList<ApprovalBean> appList = new ArrayList<ApprovalBean> ();
int tcount =0;
/*if (request.getSession().isNew()){
response.sendRedirect("./loginForCSR.jsp");
return;
}*/
//else{
if(session.getAttribute("ApprovalList")!=null)
session.removeAttribute("ApprovalList");
if(session.getAttribute("tCount")!=null)
session.removeAttribute("tCount");

but for the first time it logout automatically .And after that it works perfectly .Can anybody tell me the reason of this behaviour.

Rajani Gummadi
Ranch Hand

Joined: Dec 17, 2010
Posts: 48
Hi Vikka,

There were numerous posts on this topic in this forum, which have clearly explained the solution and to avoid pitfalls. Some of those points I recollect is not to depend on session == null, to determine the logout functionality. Instead check for the existing of objects stored in session. You can also invalidate session, which in turns removes all the attributes added to session. Please go through those posts for better understanding.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

Rajani Gummadi speaks wisely -- heed his advice.

Some more advice: use bold sparingly and only for emphasis, rather than for entire posts. I have removed the bold for you.

Also, Pplease be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session Logout Problem
 
Similar Threads
Session problem or the browser problem?
is this good for logout page
Cearing browser Cache using Servlet
IllegalStateException in servlet
session invalid problem