Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Servlets and the fly likes servlet Session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet Session" Watch "servlet Session" New topic

servlet Session

Henry Hill

Joined: Mar 05, 2004
Posts: 1
can i use Httpsession object created in get method of servlet into post method of same servlet.
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
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.
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
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.

No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
You are correct William.
Let me correct what I stated above, I wasn't thinking clearly.
Another alternative would be to:
subject: servlet Session