我是SpringMVC和FreeMarker的新手。我正在使用eclipse。这是我的index.ftl文件。我的css和图像文件位于资源文件夹中。该页面已加载到浏览器上,但freemarker模板未按预期执行。
<DOCTYPE html>
<html lang="en">
<#import "spring.ftl" as spring />
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css"
href="<@spring.url '/freemarker/css/style.css'/>"/>
<title>Spring MVC Blog</title>
</head>
<body>
<div id="image">
<img src="freemarker/image/blog-logo.png">
</div>
<div id="nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Login</a></li>
<li><a href="#">Register</a></li>
<li><a href="#">Posts</a></li>
<li><a href="#">Create Posts</a></li>
<li><a href="#">Users</a></li>
<li>
<div id="logged-in-info"> <span>Hello, <b>(user)</b></span>
<form method="post" action="menu.html">
<input type="submit" value="Logout"/>
</form>
</div>
</li>
</ul>
</div>
</body>
</html>
返回
我的Servlet根目录定义为:
<mvc:resources location="/resources/" mapping="/resources/**"/>
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/freemarker/" />
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="cache" value="true" />
<property name="prefix" value="" />
<property name="suffix" value=".ftl" />
</bean>