This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Question on HttpSession and Action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Question on HttpSession and Action class" Watch "Question on HttpSession and Action class" New topic

Question on HttpSession and Action class

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345


I have a process wherein I submit to an Action class from my jsp page, I write to the database and return the newly created database entry, create a new HttpSession and put the newly created entry in the Session as an attribute and forward to another jsp page. I do some changes in the second jsp page and write some more information to the database. Now the question here is that, I will create a new HttpSession in the first submit and put that as an attribute in that Session. Now when I call another action class from my second jsp page, I will get the Session attribute from the request and check if that attribute is not null and if it it not, then I will use the values read from that attribute. Well, the question that I have is how would I get the same Session object that I have created in my first jsp submit??

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
David Newton

Joined: Sep 29, 2008
Posts: 12617

If you get the current request's session you'll get *the* session: HttpServletRequest.getSession(boolean). Also note that unless you've explicitly disabled it, visiting any JSP page, directly or via an action, a session will have already been created.

You almost never have to create your own HttpSession locally.
I agree. Here's the link:
subject: Question on HttpSession and Action class
Similar Threads
What is the equivalent to scriptlets for invalidating the session in jsp
why Internet Explorer is different than other browsers in jsp?
doubt in session management in jsp
accessing jsp directly?
Distinction between Stateful and Standard session bean.