When you use response.sendRedirect("someLocation"), the servlet container create a new request and response object, and, if the request has not associated a session, when you call request.getSession(), a new session is created. You can use
insteand of
Thus, you send the current request and response, which have a session associated
A redirect does create a new request, but it should be participating in the same session. Changing to a forward is usually not an acceptable substitution.
Are you sure that the two servlets are in the same web app? Your redirect URL is also suspect. It should start with the context path.
Bear Bibeault wrote:A redirect does create a new request, but it should be participating in the same session. Changing to a forward is usually not an acceptable substitution.
Are you sure that the two servlets are in the same web app? Your redirect URL is also suspect. It should start with the context path.
Hi Bear!
I have a question, why changing redirect to a forward is usually not an acceptable substitution?
Precisely because a forward does not create a new request, and a redirect does. When you need a new request, a forward is not acceptable. When you don't need a new request, a redirect is not acceptable.
Both servlets are in the same web-app. Infact in the same package.
The Redirect URL without a context path also works for me.
But I have tried with a context path also. But with no results.