...
Getting started with FreeMarker is as simple as ensuring all the dependencies are included in your project's classpath. Typically, the only dependency is freemarker.jar
. Other than that, struts-default.xml already configures the FreeMarker Result needed to process your application's templates.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<action name="test" class="com.acme.TestAction"> <result name="success" type="freemarker">test-success.ftl</result> </action> |
Then in test-success.ftl
:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<html> <head> <title>Hello</title> </head> <body> Hello, ${name} </body> </html> |
...
Where mytag.tld is the JSP Tag Library Definition file for your tag library. Note: in order to use this support in FreeMarker, you must enable the JSPSupportServlet
in web.xml
:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<servlet> <servlet-name>JspSupportServlet</servlet-name> <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> |
...