Spring mvc 如何将Sitemesh 3与Spring MVC 3集成?
我试图使用Sitemesh 3控制SpringMVC应用程序JSP输出的装饰 当我点击应用程序时,似乎Sitemesh正在向SpringServlet发出请求,以尝试检索其decorator文件。这可能是,也可能不是正确的行为,但它给我带来了很多头痛 我对Sitemesh 3的理解是,它在Spring之后进行工作,即在响应对象上 我在浏览器中遇到的错误是404和日志(配置/代码如下所示): 我怀疑这是我的web.xml以及如何定义映射(URL)中的一个问题: } } WEB-INF/ |-jsp |-home.jsp |-装饰师 |-maindecotor.html 我的超级简单控制器:Spring mvc 如何将Sitemesh 3与Spring MVC 3集成?,spring-mvc,sitemesh,Spring Mvc,Sitemesh,我试图使用Sitemesh 3控制SpringMVC应用程序JSP输出的装饰 当我点击应用程序时,似乎Sitemesh正在向SpringServlet发出请求,以尝试检索其decorator文件。这可能是,也可能不是正确的行为,但它给我带来了很多头痛 我对Sitemesh 3的理解是,它在Spring之后进行工作,即在响应对象上 我在浏览器中遇到的错误是404和日志(配置/代码如下所示): 我怀疑这是我的web.xml以及如何定义映射(URL)中的一个问题: } } WEB-INF/ |-jsp
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
return "home";
}
在我的例子中,我使用了这一点来实现它。这里显示了Sitemesh 3和Spring MVC之间的集成由于没有人发布实际内容,下面是: 在
pom.xml
中添加:
<dependency>
<groupId>org.sitemesh</groupId>
<artifactId>sitemesh</artifactId>
<version>3.0.0</version>
</dependency>
<sitemesh>
<mapping path="/*" decorator="/WEB-INF/decorator1.jsp"/>
</sitemesh>
<html>
<head>
...
</head>
<body>
<sitemesh:write property='body'/>
</body>
</html>
在WEB-INF/sitemesh3.xml中添加:
<dependency>
<groupId>org.sitemesh</groupId>
<artifactId>sitemesh</artifactId>
<version>3.0.0</version>
</dependency>
<sitemesh>
<mapping path="/*" decorator="/WEB-INF/decorator1.jsp"/>
</sitemesh>
<html>
<head>
...
</head>
<body>
<sitemesh:write property='body'/>
</body>
</html>
†如果使用Spring Security,请将其放在您的Spring Security过滤器链下方。Sitemesh 2.4.2与Spring 3配合良好。链接到外部材料通常是可以的,但请确保包含一些您自己的文本,以便您的答案符合自身的优点。此链接已断开,我已修复。
<html>
<head>
...
</head>
<body>
<sitemesh:write property='body'/>
</body>
</html>