Just a few thoughts I had in emails and wanted to record somewhere more public.
On upgrading from Struts 1 to Struts 2:I’ve used both, but have never tried to migrate one to the other. Struts1 and Struts 2 and quite different – as you probably know. Struts2 was not an upgrade from the Struts1 codebase, but a completely different web framework (XWork or something?) that was rebranded as Struts2, so they work pretty differently. The only thing they really share is the name.
I think it is possible, and there seem to be guides around that can help. But I wouldn’t want to do it hehe. Struts1 is pretty ancient now though, I’d hate to be doing any new work in it. Struts2 at least has support for more modern stuff (JSON, ajax, web services etc) but I’m not a fan of Struts2 either – the whole stateful action thing just seems like completely the wrong way to do things, not only from just a Java standpoint (yes you know I’m a functional programming nerd), but ESPECIALLY for a web framework, where you’re fighting against the stateless nature of the web the whole time instead of working with it. Plus Struts2 kind of encourages you to use JSP which is probably the worst thing ever invented for the web. End rant.
Yeah I think you’re in for some pain, but it might be worth it if the old stuff really is worth keeping. I wouldn’t like to leave the old stuff in Struts 1 and have to get two different web frameworks to work together.
On what's wrong with JSP:The main issues I have with JSP is the nebulousness of it, and the ugly confusing syntax.
JSPs are compiled to Servlets, and your actions or controllers are servlets so what goes where? It’s an arbitrary decision, and you have to be very disciplined to keep that line clear. And in a team of developers it’s just not practical – you end up with business logic in the view code, and view code in the business logic. Everything becomes a big ball of mess. At least with something like Freemarker or Velocity, the template can ONLY be used as a view (mostly), so it is much easier to keep things tidy and organised, and for people to understand what should go where. Also JSP syntax just can’t compete any more with more modern templating languages.
I used JSPX for a few years on a project... The idea sounds good and it gives you a bit of that separation, but I didn’t find that much benefit – why would you want your view code to be all XML? XML is horrible! :) Modern IDE’s can cope with JSP or other templating languages just as well and it was a bit annoying to have to keep escaping with CDATA sections.
If you’re using Spring MVC, Freemarker is probably a pretty good choice - it has all the equivalent Spring MVC macros that they wrote for the JSP taglibs and is much, much nicer to use than JSP.
But take all my recommendations with a grain of salt, because I dislike the whole idea of server-side templating of HTML to start with. I’ve written a few posts in the past about what I dislike about it like this one and this one and in the past few years things have come a long way.
On getting started with Freemarker and Spring MVC:You’ll be fine with Freemarker and Spring MVC, it’s a well known and well supported combo. It’ll be fun to learn, and it genuinely is better than JSP. The concepts are not that different to what you would have done in JSP. Just remember that there is no magic, Freemarker is just a really dumb (but powerful) macro language that will spit out text (which happens to be html in this case). And that is its beauty. Spring has written their own freemarker macros which you can use, but again there is no magic in them, they are just spitting out html that will nicely work with your Spring MVC Controllers, you can look at the macros to see what they are doing. Make sure you get a good Eclipse (sigh) Freemarker plugin ;)
I’m sure you’ve seen it, but the spring docs are good to help get set up: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/view.html#view-velocity
To learn the freemarker syntax, the beginner’s guide is worth reading: http://freemarker.sourceforge.net/docs/dgui_quickstart.html
And this page is a good reference once you get into it: http://freemarker.sourceforge.net/docs/ref.html And hopefully the eclipse freemarker plugin helps out a bit too. But yeah it’s always good to look at some real working code – maybe cruise around github or see if you can find a freemarker/Spring demo project somewhere.
One little trick I would recommend: Freemarker supports an alternative syntax, basically square brackets instead of angle brackets. It can make it a little bit visually nicer to read on the .ftl pages (especially in Eclipse), having square brackets for Freemarker code, and leaving angle brackets for the HTML code. This page explains it:http://freemarker.sourceforge.net/docs/dgui_misc_alternativesyntax.html You don’t need to put the [#ftl] on every page like the link says, you can just set a switch in your web.xml once. I think it's “setTagSyntax” or something.