views:

12184

answers:

11

I need some information to understand design decision:

Is Struts a better choice than Spring MVC? I hear about Strus-Spring-Hibernae combo - Is struts used at MVC layer because its a matured framework than when compared to Spring MVC?

Any one used this combination for projects or aware of issues?

+2  A: 

Struts is definitely a mature framework, in fact it could be considered the grandaddy of the Java web framework family. Is it better than Spring MVC? I can't really say, as I don't have much experience with Struts. I do however have a lot of experience with Spring MVC and personally, I really like it, particularly since 2.5 when support for annotations was much improved.

If you're already using Spring on the back-end, the ease with which you can integrate Spring MVC is a big advantage. Maybe Struts has lots of awesome features that Spring MVC is missing, but both of them are request-based frameworks, so I'd imagine their similarities are probably greater than their differences. More specifically, I expect the difference between Spring and Struts is probably relatively minor when compared to the difference between Spring or Struts and a component-based framework, such as Tapestry or Wicket.

Don
+5  A: 

Go with Spring MVC (you're probably using Spring already) and JSTL to add data to the page.

My big complaint last time I used Struts (sometime ago and I think there was a re-write that may have addressed this) was you had to use 'form objects' for all your request parameters. This was fine when you had a simple form with known parameters but once you got into tables with varying amounts of data and checkboxes in each row you had to use something (if memory serves) called dyna-forms, which were a pain in the a*se...

Spring MVC on the other hand gives your controller objects the HTTP request and response directly giving you the power to name the parameters as meets your need.

Nick Holt
Form objects:http://stackoverflow.com/questions/353359/struts-or-spring-mvc-or-struts-spring/353578#353578
Cherian
+3  A: 

Form objects are so "Struts 1". Struts 2 appeared ages ago and made those obsolete. Struts 2 will bind request parameters directly to properties of the action. You can access the request and response directly, if need be. That's trivial.

David M. Karr
+9  A: 

Spring MVC 2.5 or higher using Annotation-based controllers is the way to go.

From my experience people using the Spring-Struts combo are shops who already know Struts and don't want to invest the time into learning how Spring MVC works.

bpapa
Definitely my choice too
Steve Neal
+4  A: 

For my money spring MVC is the way to go.

That said there isn't really again thing wrong with struts 2 (struts 1 is definitely a bit last century) I just go on the principle that you will no doubt already have spring configured in your app (who doesn't these days?) so why introduce another set of concepts and integration issues.

Spring MVC is wonderfully raw, at it's lowest level the Controller interface has just one method with HttpServletRequest and HttpServletResponse as it's parameters, and at it's best it's has complex bindings and validation. If you add webflow on top again you really do get a very complete stack.

Gareth Davis
+2  A: 

I have used both Struts 1.x with Spring and Spring MVC. Compared to Spring MVC Struts is clumsier and more rigid. I found Spring MVC quite nice to use, especially when dealing with changing customer requirements. For Spring MVC beginner SimpleFormController is a good starting point and its behavior can be modified easily.

Petteri Hietavirta
+3  A: 

I have used both, and if you have the option, I'd recommend Spring MVC.

To give you a bit of background though, my current project is Struts 1.2.9 retrofitted for dependency injection, and integrated with Spring 2.5.6.

However, the only reason for this is because this project pre-dates Spring and we're unable to port everything to Spring right now, and would like to at least be able to use dependency injection in the back end. Our Struts action are being slowly obsoleted, and hopefully we'll have completely ridden ourself of any Struts in 6-8 weeks.

Jack Leow
+2  A: 

I have used struts 1.x, struts 2.x and I'm starting with Spring MVC 2.5 I think the most flexible solution is Spring. I never found how to initialize an object at application startup with struts 2. With struts 1 I used plug-ins feature. But with spring you just define it in your beans and thats all.

Enrique
+1  A: 

Something really great with Spring is that some steps are implicit.

For example, in Spring MVC, instead of defining all actions in a struts-config.xml, you can omit all of them if they are trivial.

Having default values that are overridable as needed has many advantages:

  • fastest to write when coding
  • easiest to read (as you only read the non-default values, the default values are implicit)

The problem could be if you use little default values, then you don't gain much but have to deal with the complexity of the implicitness. But in the projects I have seen, we use 95% of default values, so the gain is huge.

The readability is more important of course, in many cases such as:

  • a new developper joins
  • you have to commit on several code branches
  • ...
KLE
+2  A: 

If you have ever used Struts2 properly, you would know that: a. it is really just Web Works (the end result of a laudable effort to "fix" the h-o-r-r-i-b-le Struts1 API) ; b. it has DI, Interceptors; c. it's API is actually more streamlined than that of Spring MVC.

For example, the Spring ThrowawayController (notably in a completely different object hierarchy than Spring's other Controllers) is almost as streamlined as a Struts2's standard Action. Both have a parameterless execute() method - Struts2 returns a "transparent" String, while Spring's Controller returns a ModelAndView (which is certainly not as "transparent").

By the way, can anyone explain (does anyone care) that the parameters for a ModelAndView() are bass-ackwards, mandating that the view object preceed the model?

In Struts2, you get a powerful (open standards-based) language called OGNL, something called a ValueStack, and Interceptors. These are noteworthy because they, in aggregate, allow for "convention-over-configuration", and make Struts2 superior to Spring MVC.

Anther thing about Spring rankles: the "decoupling" that happens in Java objects when using Spring indeed happens - trouble is that the objects are still interdependent, instead now the interdenendencyis expressed in XML (and a recompile is needed if the XML mappings change)! You also use bytecode instrumentation (via the container) to accomplish the "magic". And really, if dependent class A has a setter for class B, can it really be said that it does not know about (have a dependencey upon) class B? Be honest.

+1  A: 

If you have a database with loads of tables / columns / data and require loads of SQLs and datasets..etc use Spring MVC as it goes so well with HIBERNATE and it's pretty easy to use...and config. with DB sessions already handled for you..etc

If you are more focus on others...i.e Interface, views...JSF..etc.. I'd suggest Struts probably sufficient.in that case..

I'd suggest never do Struts + Spring + Hibernate...i did that once. it's a nightmare!!!..spent me so many effort on this..like checking libraries for both framework totally not worth at all...

Hope that helps!

henry