问题
There seem to be a lot of template languages for both Java (e.g. JSP, JSTL, Freemarker, Velocity, ...) and for Javascript (e.g. Mustache, Ext's XTemplate, Jquery templates, ...) but is there one which have an implementation for both?
Ideally I'd like to be able to have an template which can be evaluated either on the server or on the client side without too much hassle switching over.
回答1:
Google Closure/Soy templates.
The Wikipedia Page for Web Templating Languages reveals another one: Casper.
Both these solutions don't use a common template file which is directly evaluated in JS or Java. The template must first be compiled into an intermediate JS before evaluation on the client. (For Closure, this is fairly easy to do with ant
and an included SoyToJsSrcCompiler.jar
command line tool. Not sure about with Casper.)
EDIT: Another possibility is Mustache, which does not require templates to be compiled.
来源:https://stackoverflow.com/questions/8871425/cross-java-and-javascript-template-language