March 07, 2005
Spring or Struts?
My company is deciding on the toolset that we'll be using for our next generation of web applications. Java was a shoe-in after my Python suggestion was shot down early in the discussion. :-(
But deciding upon Java is only the first step - you need a whole bunch of stuff to go along with it. One of our recent projects was intended to be a pilot, and I was fairly happy with the toolset that we used for that, so mostly we'll be updating that list.
In the end, though, we ended up not using Hibernate and not using Struts - we wrote our own. This time, I'd like to use frameworks for these layers rather than building our own workable but time consuming and frankly far inferior versions.
Hibernate looks by far the front runner for the persistence layer, but selecting the MVC framework isn't so easy. Struts is certainly the de facto standard here, but I'd like to be using Spring for other things in any case, and I gather that its MVC component is really good, so I lean towards using that too.
Good idea? Bad idea?
There are a few other additions to the original toolset:
- We'll be using JSP (and JSTL) for our View layer. Unfashionable, I know, but since JSTL came along and removed the need for virtually all of those nasty scriptlets, I find JSP to be rather nice.
- EMMA for unit test code coverage reporting
- iText if we need any PDFs generated
- Joda Time
Anyone think that we shouldn't be using any of this stuff? Anything essential that I'm missing?
Posted to Java by Simon Brunning at March 07, 2005 10:45 AM
You might want to consider using WebWork for the web, with Spring as the glue - I'm not sure Spring's web stuff is as advanced as WebWorks'.
Struts is of course the de-facto standard for the MVC layer of webapplications, Spring however is much more flexible and works together niceley with the rest of Spring (this also holds for Struts, although the integration is somewhat less transparent). Compared to Struts Spring is (a bit) more elegant wrt to usage of design patterns and the ease of binding data to domain objects (with Struts for example you have to create ActionForm objects that you'll be using to transfer data from the web-tier to your domain objects and vice versa).
I guess it all depends on your needs. You should think about existing knowledge within the team. Are there people that are already familiar with Struts?
Next to that, integrating PDF views with iText is a breeze with Spring MVC through the use of the AbstractPdfView, implementing the common Spring View interface.
p.s. as for the other components you're listing, there's nothing I wouldn't use although presonally I'm not a big fan of abstractions over such basic infrastructural stuff as java.util.Date. I haven't had a decent look at Joda Time though to be honest, so I can't really judge here.
I find the best way is to list all the stuff that's already on your CV. That's what you don't want to use.
Then look at all the stuff out there that you *want* to have on your CV and use that.
WebWorks Arrgh, not *another* one! Is Spring missing anything vital? If I mention Yet Another Framework, my team are going to lynch me...
We have little real-world Struts *or* Spring experience here, so existing knowledge isn't a factor, really.
Joda - well, I'm used to Python's date and time handling, so java.util.Date just doesn't do it for me.
Darren, you old cynic, you. ;-)
I'd suggest Spring, not Struts, but I'd also strongly suggest having a look at Matt Raible's Equinox project as a jump-start - https://equinox.dev.java.net/. He also did a comparison presentation here - https://equinox.dev.java.net/framework-comparison/WebFrameworks.pdf - which might be of interest.
At the risk of spouting heresy -- the tools chosen for one project may not be the best for another.
Well, AppFuse may not be for rookies, but Equinox might be! When I asked Matt about the difference, this was his summary...
The main things are that AppFuse has lots of security features and user-management. It also uses XDoclet to reduce DRY (don't repeat yourself) and generate deployment descriptors. Equinox is much simpler and (IMO) easier to understand.
If you're likely to need all that either gives you (and I'd suggest that that's likely with Equinox, at least), then you'll have to be get up to speed on it, and it's easier to do if you can start with a working project that actually pulls the bits together and does something!
[Actually, given a free choice, I'd be lookihng at Subway (Python - combining CherryPy, Cheetah & SqlObject) or Wicket (Java - Tapestry without the XML) but for your stated requirements, I'd use Equinox to jump-start things.]
Maybe this is old news to you - I have been out of touch for eight weeks while on vacation - but I understand that work on Struts has been halted. They've called the current incarnation of Struts "Struts Classic" and sprawned a new "Struts Shale" based on JSF.
Well, if I had to use Java instead of Python I'd look for a new job. :-)
Though there's always Jython.
Struts isn't so much dead as it is completed, I thought. That isn't a reason not to use it, is it? (There will be bug fixes - just no new functionality.) And the new Struts, Shale, isn't production ready.
As for Sun's new persistance API, well, again it's not much good to us until there's a production ready implemetation. The JSR isn't even finished yet AFAICS.
We are looking for state-of-the-art, not bleeding-edge.
As I've used all three frameworks you mention here:
Don't use Struts! People keep telling me that Struts can be used correctly and efficiently my colleagues and I failed miserably. It's just too easy to mess up.
So take either Spring or WebWork. I didn't notice that much difference. Everything I wanted to do was easy to do and just worked (most of the time).
To make a decision, read what Matt has written and hang out at the forums/lists.
Regardless of your decision- you can be sure, if you run into problems (and you will) your colleagues will kill you ;)
JSP plus Servlet can do very good job on View and Control part. I cannot see why have to use Struts.
If you take a look at Matt Raible's comparison, he doesn't opt for Spring. It's either Struts or Tapestry. I've been using Struts for a while, and tested Spring MVC recentrly. Springs MVC looks more logical, but it's still a way back when it comes to supporting the developers (lack of decent tag library, for example).
as a persistence layer, check out cayenne ( http://objectstyle.org/cayenne ). very powerful, easy to use ORM. if you came across apple's WebObjects, and liked what EnterpriseObjects was like for java 1.1, you'll find this is pretty much a modern java ( collections, etc) reworking of it.
but seeing as this thread seems controller-oriented, i use and recommend struts for the smallest ( well, maybe not _the_ smallest - per^h^hython still has a few uses ;) ) to the largest projects.
form handling via ActionForm's, or the code-free DynaActionForm, plus all the goodies you get out of modules and tiles makes it the defacto standard for a very good reason: pure elegant power.
check out the scaffold classes, and especially the DispatchAction. if you've worked with struts and have been coding seperate Action's for each and every little thing, then you've really missed the point. i usually slip most of the actions i need into one DispatchAction subclass per module, plus a couple of system-management extras as needed. if you use eclipse, you can even get the stubs for the common actoins ( create, read, update, delete, list ) created for you every time you subclass DispatchActoin by tweaking the class creation templates.
as for the view side of things, tiles provides everything you could want to really break down your task into independent logical components, making maintenance a breeze. i prefer jsp, but i know someone who prefers velocity, i'll leave that up to you.
dont be afraid to spend a little time working in xml struts and tiles configuration files: you'll save yourself a heap of time coding.
in short: use struts. spend a week trawling the web for best practices & tips, or event better go buy yourself the Manning book (http://www.manning.com/husted). one week reading that will save you months of coding.
you have to pay for Struts-Layout!
There are a lot of free libs on the market you can use for free. Nayway Struts-Layout is mix of struts + JSTL = you can write own if you have time and want to spent some money