This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

About Spring MVC vs. Struts

Aug 12th, 2004, 12:47 AM

My question is which is better. which should I use in my project.
can anybody list the advantage that springmvc or struts is good than the other one.
whether the spring + struts is a good choice? and why? thanks.

Comment

If you're currently using no MVC framework, and your web app is anything beyond trivial then you will see benefit from using either Struts or SpringMVC.

Clearly in a Spring Web forum, you're likely to come across more people who think Spring is better. Go to a Struts forum and you'll likely as not find the opposite. Obviously they both serve similar needs so there's a lot of functional and design similarities, but which is 'better' however is slightly subjective.

A couple of guidance points are;

Struts has been around a long time and has been popular for years - there's a wealth of knowledge about it in the user community and more literature around (for now!).

SpringMVC wouldn't have been developed if everyone thought all was rosy in the Struts garden. It's much more flexible and powerful.

Struts imposes dependencies on your Controllers (they must extend a Struts class), Spring doesn't force you to do this although there are convenience Controller implementations that you can choose to extend.

If you're going to use Spring for other middleware services, and you have no Struts expertise in house, then it would be simplest to go with SpringMVC. If you know Struts well or have team members who do, or you already have a Struts project, it may make sense to stick with it.

Comment

If you want a bunch of taglibs that generate form fields and so forth, Struts is probably the better choice.

I think Spring MVC takes a cleaner approach than Struts.

In any case, it's very easy to integrate Struts and Spring. I had never used Spring with Struts until recently, and I found integrating them to be a complete no brainer. (I followed the instructions and things worked properly the first time, and that almost never happens.)

Comment

I agree totally with Darren. I also agree with everything that was posted from Rod's book on the Struts forum. That forum thread gives you a good sense of how a person who has only ever used Struts and never used SpringMVC will look at the question. Unfortunately, it does not give you a good idea of the benefits of SpringMVC.

I converted my main project from Struts to SpringMVC about 5 months ago, and I will never look back. All of the people who defended Struts ActionForms as a good way to get user input from the request to objects definitely never used SpringMVC (then again, it wasn't even out at that point...I think).

In my opinion the most powerful aspect of SpringMVC is the databinding. Instead of writing a lot of conversion code in your controller, you will write "controller" code in your controller and leave the databinding up to the framework. You can bind user input directly to domain objects. This has saved me a tremendous amount of time, and greatly simplifies the web tier of my app.

The biggest disadvantage of SpringMVC is the lack of the equivalent of Struts' html tag library. The Spring taglib is much more flexible, as it does not output any html code, but it takes more code to get the same input tag on the page. The good thing is that macro tags are currently being created for SpringMVC in the following flavors: velocity, freemarker, and jsp 2.0 *.tag files. Besides, it's simple to create your own--I have a mostly complete set of my own jps .tag files. Again, my opinion, your choice of MVC framework should not depend on a single tag library.

The Struts codebase was not written by Rod and Juergen...unfortunately...it's quite poor IMHO. I have learned more about OO and good design in general from looking at the Spring source than I have from any other open source project.

Use SpringMVC! You will be saving yourself a huge headache when you decide to convert later. If you're still torn after this blatant advocation of SpringMVC (all from hard experience I might add), do a sample app with each framework and use whichever one you like better, but be sure to bind more than Strings to your domain objects to realize the full benefit of Spring databinding.

Comment

I was in the same position. Trying to convince management to use other frameworks other than struts is very difficult. It really is the defacto standard for building web apps. There are huge amount of books and a number of developers (at my work) have used it. I'm sure that this is the typical scenerio.

Fortuately, I convinced them to use the spring framework because frankly anything is better than EJBs and entity beans. I'm very happy that Rod or whoever wrote great documentation to convince the higher ups (but not good enough for the spring mvc ...).

Comment

Yes, I was amused at the reaction of the some of the Struts guys to the criticisms in my book early last year. In fact the reviewers of Expert One-on-One J2EE were without exception negative about my criticism of Struts--not because they disagreed, but because they thought it was pointless, as Struts was here forever.

However, things have changed a lot since then. Most of those criticism are now fairly widely accepted as valid. I think it's fair to say that some of the people who posted on the Struts mailing list back then may not hold the same opinion today. If Struts 2.0 ever sees the light of day it will almost certainly represent a major change in approach.

One way or another, I think it's pretty clear that domination of Struts is coming to a close, with JSF, Tapestry, Spring MVC and WebWork all growing rapidly in popularity.