File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 364
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:
I agree. Here's the link:
subject: servlet Session
It's not a secret anymore!