1

I have a problem with Struts2, the problem is, the client want the styling of the web apps is dynamic, for example is, i can put the template (.html / .ftl) on /apps/template/path where all the logic on war, can i do that?

i've been searching all over google and that style of code is belong to freemarker. but if using freemarker, i have to code using servlet (i dont wanna do that).

Can you give me the hint/solution, or it really cant be in Struts2?

Roman C
  • 49,761
  • 33
  • 66
  • 176
fahmi
  • 705
  • 2
  • 10
  • 23

1 Answers1

2

if using freemarker, i have to code using servlet

No, FreeMarker doesn't need Servlets instead of Actions. FreeMarker is fully integrated in Struts2, it just needs the library in your libs directory and some little configuration in struts.xml and web.xml.

According to Struts2 documentation,

Template Loading

The framework looks for FreeMarker templates in two locations (in this order):

  • Web application
  • Class path

This ordering makes it ideal for providing templates inside a fully-built jar, but allowing for overrides of those templates to be defined in your web application. In fact, this is how you can override the default UI tags and Form Tags included with the framework.

In addition, you can specify a location (directory on your file system) through the templatePath or TemplatePath context variable (in the {{web.xml)}. If a variable is specified, the content of the directory it points to will be searched first. This variable is currently NOT relative to the root of your application.

So, if you want to use .FTL files (FreeMarker Templates) INSTEAD of JSP files, you can put them outside the ear, in the file system.

Like this (web.xml):

 <!-- FreemarkerServlet settings: -->
  <init-param>
    <param-name>TemplatePath</param-name>
    <param-value>/apps/template/path</param-value>
  </init-param>
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243