Visit our blog

News & Events

Article: Get a better handle on Struts actions, with Spring

Get a better handle on Struts actions, with Spring, a DeveloperWorks article by George Franciscus, provides a detailed look at the 3 primary variations in how the Struts web UI framework may be integrated with Spring.

 

Comments

Good Article contains a possible Struts No No

I thought this artilcle was exceptionally good, but was concerned that the third recipe demonstrates DI in a struts action class by 'setting' the BookService member variable.

I've always understood that Struts action classes are similar to Servlets, so use of member variables (unless they are thread safe) is to be avoided.

Yes Yes

Since struts actions are cached, they must be thread-safe. That does't mean that you can't use instance variables. If those instance variables are thread safe, and the objects they reference are thread-safe, then everything is good. Servlets suffer the same problem because Servlets are pooled by the container. By default Spring delivers singletons. As long as the services are thread-safe (as all singletons should be), there is no danger.

 

Newsletter Subscription

Our monthly newsletter is packed full of techniques, tutorials, tips and tricks to get you on your way to Spring nirvana. View Archive