Jump to content

HttpSession in JSP when using forward(Request, Response)

java_on_fire's Photo
Posted Jul 21 2010 07:47 AM
3057 Views

Something i'm not understanding. I have two JSP pages, index.jsp that submits to servlet A and result.jsp that gets the (request, response) through RequestDispatcher from servlet A. In servlet A, i get a session from HttpSession and set its attribute with a user name parameter i get from index.jsp.

When i test above application with Internet Explorer cookies disabled by writing this simple line of code <%= session.getAttribute("username")%> in the result.jsp, the result.jsp page shows me the input from the index page? how so? shouldn't the output from the result.jsp page be null because cookies were disabled and i didn't use URL rewriting!!

I was experimenting with this yesterday and instead of forwarding the (request, response) to the JSP, I used the PrintWriter inside my servlet and the result.jsp showed null!?

Tags:
0 Subscribe


2 Replies

+ 1
  java_on_fire's Photo
Posted Jul 22 2010 07:45 AM

for those who are following this and looking forward for an answer, i got this from another forum.

"Tolls"
You forward to the JSP, but you still haven't left the server. It's no different (frankly) to a method call. It doesn't go to the client so cookies and URL rewriting is irrelevant.
 : Jul 22 2010 07:47 AM
Thanks for coming back with the answer.