Groovy and Tomcat, Pt4 – Groovy Servlet Pages

Groovy Server Pages (GSP)

Setting up GSP is as easy as setting up scripts.

Add following to the project:

- groovy.jar
- groovy-json.jar
- groovy-servlet.jar
- groovy-templates.jar
- groovy-xml.jar
- antlr.jar
- asm.jar

web.xml


<servlet>
 <servlet-name>GroovyPages</servlet-name>
 <servlet-class>groovy.servlet.TemplateServlet</servlet-class>
 </servlet>
 <servlet-mapping>
 <servlet-name>GroovyPages</servlet-name>
 <url-pattern>*.gsp</url-pattern>
 </servlet-mapping>

And then just create your .gsp file:


<html>
<head><title>Groovy Pages</title></head>
<body>
<p><% println "hello world" %></p>
</body>
</html>

Navigating to the gsp url gives me the following:

Still easy as 1-2-3.

The next part will be up later tonight as it’s under construction. It will feature a project that ties all the different groovy parts together into one project.

Until then, take care,
Eek.

Add Comment Register



Leave a Reply