我正在尝试使用Spring MVC 3和Spring Security 3配置Tiles 2.2并将其集成到 webapp 构建中,但我遇到了一些困难:
- 没有显示瓷砖定义。
- 也没有加载静态资源(css、js),即使是从不使用 Tiles 的页面调用的资源。
注意 1:当我单击不使用 Tiles 的 jsp 文件的 .css 和 .js 链接时,我总是被重定向到索引页面。
注意 2:在添加 Tiles 之前,一切正常。
web.xml
<servlet-mapping>
<servlet-name>myapp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>myapp</servlet-name>
<url-pattern>/myapp/*</url-pattern>
</servlet-mapping>
myapp-servlet.xml
<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" />
<!-- JSP View Resolver -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- Tiles View Resolver -->
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" >
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" >
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
瓷砖.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd" >
<tiles-definitions>
<definition name="baseLayout" template="/WEB-INF/pages/layouts/base-layout.jsp">
<put-attribute name="header" value="/WEB-INF/pages/tiles/header.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/pages/tiles/footer.jsp" />
</definition>
<definition name="template2-tiles" extends="baseLayout">
<put-attribute name="title" value="FixealaBA" />
<put-attribute name="body" value="/WEB-INF/pages/template2.jsp" />
</definition>
</tiles-definitions>
基本布局.jsp
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<head>
<title><tiles:insertAttribute name="title" ignore="true" /></title>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/myjquery.js"></script>
<link type="text/css" href="${pageContext.request.contextPath}/resources/css/mystyle.css" rel="stylesheet">
</head>
<body>
<tiles:insertAttribute name="header" />
<tiles:insertAttribute name="body" />
<tiles:insertAttribute name="footer" />
</body>
</html>