• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session Logout Problem

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 48
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic