我无法使用Tiles 3获得一个非常简单的freemarker模板。网站上的示例似乎是针对版本2.x,因为编程配置引用了不存在于tile 3中的类。
通过以下配置,我的模板按原样显示(即它不包含任何图块)。我该如何解决这个问题?
渲染页面时
使用url:http://localhost:8080/TilesFreeMarker/myapp.homepage.tiles
时,我得到的内容与下面templage.ftl文件中的内容完全相同。如果我用jsp&(和所需的标签)替换所有ftl文件,那么示例就会按预期运行,但我需要freemarker功能。
Web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<listener>
<listener-class>org.apache.tiles.extras.complete.CompleteAutoloadTilesListener</listener-class>
</listener>
<!-- Configure so anything ending in .tiles will be processed by tiles -->
<servlet>
<servlet-name>Tiles Dispatch Servlet</servlet-name>
<servlet-class>org.apache.tiles.web.util.TilesDispatchServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Tiles Dispatch Servlet</servlet-name>
<url-pattern>*.tiles</url-pattern>s
</servlet-mapping>
</web-app>
template.ftl
<#assign tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"]>
<!DOCTYPE>
<html>
<head>
<title>
<@tiles.getAsString name="title"/>
</title>
</head>
<body>
<table>
<tr>
<td colspan="2">
<@tiles.insertAttribute name="header"/>
</td>
</tr>
<tr>
<td>
<@tiles.insertAttribute name="menu"/>
</td>
<td>
<@tiles.insertAttribute name="body"/>
</td>
</tr>
<tr>
<td colspan="2">
<@tiles.insertAttribute name="footer"/>
</td>
</tr>
</table>
</body>
</html>
</#assign>
header.ftl
<div>The Header</div>
menu.ftl
<ul>
<li>Menu Item</li>
<li>Menu Item</li>
<li>Menu Item</li>
<li>Menu Item</li>
</ul>
body.ftl
<div>The Body</div>
footer.ftl
<div>The Footer</div>
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.quaternion</groupId>
<artifactId>TilesFreeMarker</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>TilesFreeMarker</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>