• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet Session

 
Henry Hill
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i use Httpsession object created in get method of servlet into post method of same servlet.
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I don't think so, you must create a new reference to HttpSession in the doPost method unless you either create an instance variable(which is not recommended) or another example is to pass both the HttpServletRequest and HttpServletResponse as well as the HttpSession to a single method called by both the doGet and the doPost methods. The HttpSession object is not implicit like it would be in a JSP page.
I hope this helps.
Craig
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From doGet(request, response)
call doPost(request, response)
in doPost call request.getSession()
but then all of your pages would have to call doGet so this may not be what you're looking for.
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct William.
Let me correct what I stated above, I wasn't thinking clearly.
Another alternative would be to:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic