Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Logout Problem

 
vikka sharma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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.

 
Rajani Gummadi
Ranch Hand
Posts: 48
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic