• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2 in Action: Session State

 
Ranch Hand
Posts: 125
1
Clojure Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of my biggest hassles with Struts 1.x is managing complex session state on the server. In some places, my Struts 1 action class has to read form values, and lookup data corresponding to client cookie settings in the database, and pull a host of data out of HttpSession attributes.

So:
1. Does Struts 2 have any particular tools to make managing session state easier? If so, are the tools covered in the book?
2. If Struts 2 does not have any tools for managing session state, are there any best practices you recommend? Would they be covered in the book?
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Struts 2, your action class is a POJO. The instance variables within the action class maps to the form elements in your JSP. The setters in your POJO (action class) are invoked to inject the values from the HTTP request into your POJO. So from within your action class, you do not need to explicitly deal with the HttpServletRequest class anymore.

Hope this helps.
 
Michael Swierczek
Ranch Hand
Posts: 125
1
Clojure Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I have played with Struts 2 a little, and I saw that the action classes are POJOs. That helps with forms, and it's certainly a big improvement over Struts 1.x. (I also understand that each request gets its own action class, instead of the Struts 1.x model of one class per mapping. That's another help.)

But I'm more concerned with thing like which page the user was on when they selected the current Action, which language they selected, what their previous selections were, and so forth. Struts 1.x, to my knowledge, does not have any tools to make that kind of state tracking easier.

So we would write a massive POJO with a list of previous pages, current page, and all sorts of other settings, and the beginning of each Struts 1 Action class would be ApplicationState aState = (ApplicationState)request.getAttribute(Constants.APPLICATION_STATE); It worked, but it has its own problems and it seems like we are forced to write more status-checking code than should be necessary.
 
Ranch Hand
Posts: 471
Mac OS X Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can still access the session in struts 2. Here is a page on the subject. Here's another one. And heres a third pretty useful one.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic