• 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

Problem in Servlet Session

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I am getting session not recognized problem for the first time I click any servlet application. But the application works fine for JSP applications. The same code was working fine in another Server. Only Tomcat has been upgraded from 3.x to 4.x

Can you please suggest any possible solution for this scenario.

Thanks & Regards
Deepak
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


But the application works fine for JSP applications.


That is probably due to the fact that every JSP by default include an implicit session.


The same code was working fine in another Server. Only Tomcat has been upgraded from 3.x to 4.x


If the same code works well in another Servlet Container, but not in Tomcat, seems to me that Tomcat has a problem. You might wanna check the issues page of you specific version. Can you upgrade to the most recent version of Tomcat? It seems to me that the recent version doesn't has that kind of problems.

[QB}
Can you please suggest any possible solution for this scenario.
[/QB]


Upgrade your Servlet Container. If that's not possible, describe the problem in more detail so we can try and help you.

Ice
 
Deepak Prasanna R
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Ice

We are not in a position to migrate the Tomcat version.
The first time we click the servlet, am getting the session is not getting recognized. Second time if i click the same servlet, it gets recognized.
If i click any JSP links before the Servlet, then the Servlet is working fine on first click itself.

Can you please suggest a solution based on this.

Thanks & Regards
Deepak
 
Ice Penov
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Deepak Prasanna R:
Thanks a lot Ice

We are not in a position to migrate the Tomcat version.
The first time we click the servlet, am getting the session is not getting recognized. Second time if i click the same servlet, it gets recognized.
If i click any JSP links before the Servlet, then the Servlet is working fine on first click itself.

Can you please suggest a solution based on this.

Thanks & Regards
Deepak



Because you did not supplied enough information, i'll have to make assumptions:

1. You have cookies enabled
2. You have the following problem: Your session is created before you invoke the problematic servlet to join the pre-exising session. You do that by using HttpServletRequest.getSession(false) - to get only the pre-existing session, not to create a new one. So, if you're using getSession(), try using getSession(false) to detect whether the Container version has a problem with joining a pre-existing session. You'll get NullPointerException if the Container has failed to join the session and you try to use the session.

If you invoke any JSP it will automatically create a jsp session( by using the default value of the attribute in the page directive), so the next invoked servlet will already has a session to join. Try adding the following attribute session='false' to the page directive in your JSPs, and try invoking the servlet after you have invoked any of those JSPs with this session='false' attribute set. Tell us what you get.

When you're testing the application, keep track of the cookie : JSESSIONID, to see which session, where is created. If you don't now how to do it, you can use IE or Firefox menus to view cookies. That will shed some light about your problem.

In lack of information, I can advice you to try getSession(false) to only join a pre-existing session, keep track of when JSESSIONID cookie is created, and try to solve your problem. If you're still having problems, tell us what kind of errors/issues you got when you tried those things. That will help us greatly to properly diagnose your problem.

By far away, if you're doing things right( like creating and joining session the right way ), it seems a Container issue. Have you checked the docs for your Container version to see whether this what you're describing is a known issue ?

Ice
 
Deepak Prasanna R
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Ice

The problem was with the cookie and it was not getting encoded when it was called through the servlet, So it was getting failed for the first time. Now the application works fine.

Thanks for your support.

Thanks & Regards
Deepak
 
Ice Penov
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad I could help, Deepak.
 
reply
    Bookmark Topic Watch Topic
  • New Topic