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:

  • Log4j
  • 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
  • jMock
  • displaytag

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
Comments

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'.

Posted by: sam on March 7, 2005 11:53 AM

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.

regards,
Alef Arendsen

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.

Posted by: Alef Arendsen on March 7, 2005 11:55 AM

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.

Posted by: Darren on March 7, 2005 12:06 PM

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. ;-)

Thanks, all.

Posted by: Simon Brunning on March 7, 2005 12:13 PM

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.

Posted by: Gwyn Evans on March 7, 2005 01:33 PM

At the risk of spouting heresy -- the tools chosen for one project may not be the best for another.

Posted by: Brian McCallister on March 7, 2005 01:45 PM

Equinox[1]? I did have a look at AppFuse[2], but I though we'd leave that for a while until we were more familiar with the frameworks that we were using. After all, AppFuse is not for rookies[3].

It's true that one size doesn't fit all - but you can't know *everything*. We want to get our people learning some stuff.

[1] http://equinox.dev.java.net/
[2] http://raibledesigns.com/wiki/Wiki.jsp?page=AppFuse
[3] http://raibledesigns.com/page/rd?anchor=appfuse_not_for_rookies

Posted by: Simon Brunning on March 7, 2005 01:47 PM

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.]

Posted by: Gwyn Evans on March 7, 2005 03:58 PM

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.

http://www.apachenews.org/archives/000552.html

Posted by: David Pinn on March 7, 2005 06:51 PM

Change on the persistence front too:
http://java.sun.com/j2ee/persistence/faq.html

Posted by: Andrew Crump on March 7, 2005 09:31 PM

Well, if I had to use Java instead of Python I'd look for a new job. :-)

Though there's always Jython.

Posted by: robin on March 8, 2005 03:30 AM

As David said... http://www.manageability.org/blog/stuff/official-struts-demise

Posted by: jez on March 8, 2005 05:31 AM

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.

Posted by: Simon Brunning on March 8, 2005 08:45 AM

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 ;)

Posted by: Fabian Crabus on March 8, 2005 03:02 PM

JSP plus Servlet can do very good job on View and Control part. I cannot see why have to use Struts.

Posted by: Lisa on March 19, 2005 12:11 AM

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).

Posted by: Barak on March 27, 2005 02:14 PM

Matt also chose WebWork actually, here is the last slide of his comparison:

Which would I choose?
• Quick and dirty project?
• Struts because I know it best
• Massive enterprise project?
• Tapestry for its reusable components
• If I got a job as an open source developer?
• WebWork because using it requires you to dig into the frameworks

I got this from

http://64.233.179.104/search?q=cache:Isd5XqrvfOoJ:blog.sunmast.com/alex/archive/2004/12/13/1047.aspx+webwork+spring+comparison&hl=en&lr=lang_zh-TW|lang_en%20target=nw

Posted by: Li on April 8, 2005 07:00 AM

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.

jd

Posted by: jay on April 30, 2005 02:17 PM

Please share ur comments on this

http://csblogs.blogspot.com

Chandrasekhar S

Posted by: Chandrasekhar on May 23, 2005 09:49 AM

You should have a look on Struts-Layout taglib, more complete than DisplayTag :
http://struts.application-servers.com

Posted by: CJ on June 22, 2005 12:25 PM

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

Posted by: AGO on September 20, 2005 06:15 PM
Post a comment
Name:


Email Address:


URL:



Comments:


Remember info?