Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating from JSP to Freemarker

I'm working on a Spring 2.5 project where four different webapps have duplicate JSPs (they were all derivations of the same webapp). I want to introduce Freemarker so I can externalize and reuse these templates across all the webapps. However, I want to approach this iteratively since it's going to be a big project, so I need JSP and Freemarker to live in harmony for awhile.

I know Spring allows chaining multiple ViewResolvers, but JSP's InternalResourceViewResolver and Freemarker's FreeMarkerViewResolver both state that they need to be last in the chain. I've tried to chain them anyways and specify an order priority, but no luck.

Freemarker seems to support JSPs to some degree, though I don't really see how I could use that in a gradual migration (http://freemarker.sourceforge.net/docs/pgui_misc_servlet.html).

Does anyone have any ideas?

like image 216
Stano Avatar asked Jan 20 '12 16:01

Stano


People also ask

Which is better FreeMarker or Thymeleaf?

FreeMarker has all the essential features to generate HTML for most of the cases, and it is easier to learn. So it is not a bad idea if you want to use it. However, Thymeleaf is the way to go if you want to add custom functionality to your templates.

What is spring boot FreeMarker?

FreeMarker is a server-side Java template engine for both web and standalone environments. Templates are written in the FreeMarker Template Language (FTL), which is a simple, specialized language. Note: Spring Boot recently changed the default extension from . ftl to . ftlh.

Can I allow users to upload templates and what are the security implications?

Can I allow users to upload templates and what are the security implications? In general you shouldn't allow that, unless those users are system administrators or other trusted personnel. Consider templates as part of the source code just like *.


1 Answers

In Spring 2.5 you'll probably have to use a BeanNameResolver since you can't have two URL resolvers, see this thread. This got much easier in 3.0 where you can order resolvers.

References

  • NixMash Post: The Move from Velocity to FreeMarker with Spring Boot

  • A Review of Java Template Engines - DZone Web Dev

like image 178
2 revs Avatar answered Oct 01 '22 13:10

2 revs