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

What happened to the session?

 
chris walker
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
 
Ra Re
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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!
 
Charles 'King
Ranch Hand
Posts: 56
Eclipse IDE Postgres Database Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic