• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

What happened to the session?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This problem only happens on server. It never occurs on local machine.

Problem: I add user to session and I check to make sure user is in session (it is). Then I send to ProfileServlet and user is no longer in session. In fact, session has a new id.

I have ProcessLoginServlet that adds the user to the session and redirects to the user's profile page.
The last 4 lines of code in ProcessLoginServlet are:


The first line of code in ProfileServlet is:


and this is what is printed to the log file:


Forgot to mention that the 2nd time I attempt to login it works fine.

Seriously, this goes against everything I have learned about sessions. I'm obviously doing something wrong here but can't figure it out.

Please help. Thanks
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe the problem resides on the response.sendRedirect("") you are using.

Is there any reason to use the response.sendRedirect("") instead of the RequestDispatcher.forward(request, response)? I mean, it seems you are using it inside the same web application, so I find more suitable to use a forward than a redirect.

Search information about these two methods and maybe here is the problem. Check out this link...

http://www.theserverside.com/discussions/thread.tss?thread_id=742#201249

Good luck!
 
Ranch Hand
Posts: 56
Eclipse IDE Postgres Database Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your problem is this line:



For testing purposes and if both resources are in the same application; modify that line to this and report back:



Employing sessions across JVMs requires a sessionactivation listener. Is your web application in a distributed environment?
 
chris walker
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You guys are awesome! Due to my ignorance I thought you always had to supply an absolute url to response.sendRedirect. I change code as Charles suggested and it worked. I'm sure Raimon's way would of worked also.

Thanks for helping.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic