Using GSP views in plain Spring MVC without Grails

后端 未结 3 1900
借酒劲吻你
借酒劲吻你 2021-02-08 22:16

I would like to use GSP views instead of JSP/JSTL views in a plain old Spring MVC application. I have added a groovy.servlet.TemplateServlet to web.xml like this:



        
相关标签:
3条回答
  • 2021-02-08 22:58

    We have extracted GSP from Grails, customized it for Spring MVC applications and improved configuration support. Please see our tool Rabbtor. We don't provide it open source, but usage is free of charge and we have been using it in our own applications. GSP for Spring Boot depends on Spring boot, it is not maintained and some tag libraries depend on Grails. We removed these dependencies, created our own custom tag libraries which better suit Spring MVC apps.Most tag libraries are supported and have similar implemantations to Spring JSP tags.A data-bound form tag library is provided and also you can register your tag libs or packages.

    0 讨论(0)
  • 2021-02-08 23:04

    Today GSP for Spring Boot was just released. This provides the ability to use GSP instead of JSP in a regular Spring web application. You can see an example here: https://github.com/grails/grails-boot/blob/master/sample-apps/gsp/script/templates/index.gsp

    0 讨论(0)
  • 2021-02-08 23:09

    Instead of using a TemplateServlet, you could have also used a GroovyPagesServlet for that purpose (I haven't tested that, just looked at Grails' web.xml and the class' code).
    The latter requires a Spring bean to be setup, named groovyPagesTemplateEngine, and typed GroovyPagesTemplateEngine (GStringTemplateEngine in this case).

    Configuring the view layer with an InternalResourceViewResolver is correct. You'll have assigned a GroovyPageView.

    GSPs, by default, are not configured to perform HTML output escaping. To configure that, change grails.views.default.codec from none to html in Config.groovy. See this article for more information.

    0 讨论(0)
提交回复
热议问题