spring MVC 中的 apache tiles 问题(查看渲染路径而不是内容)
apache tiles issue in spring MVC( view rendering path instead of content)
我正在使用 apache tiles 开发我的第一个 spring MVC 项目。但是,我对呈现的内容有疑问。
渲染路径 (WEB-INF/jsp/index.jsp) 而不是 index.jsp 中的内容(即来自 spring MVC 独有的 Hello)和页脚它呈现 (WEB-INF/layouts/footer.jsp) 而不是
© laxmon philip
请参阅我的输出的附加屏幕截图。 localhost:8080 output screenshot
这是我的第一个 spring MVC with apache tiles。请让我知道我在这里做错了什么。
我的tiles-定义如下
general.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="common" template="WEB-INF/layouts/classic.jsp">
<put-attribute name="footer" value="WEB-INF/layouts/footer.jsp" />
</definition>
<definition name="index" extends="common">
<put-attribute name="title" value="JAVA BLOG AGGREGATOR" />
<put-attribute name="body" value="WEB-INF/jsp/index.jsp" />
</definition>
</tiles-definitions>
classic.jsp 模板
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:getAsString name="title"/></title>
</head>
<body>
<tiles:insertAttribute name="body"/>
<br><br>
<center>
<tiles:insertAttribute name="footer"/>
</center>
</body>
</html>
footer.jsp模板
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
© laxmon philip
index.jsp 页
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<h2>Hello World From Spring MVC</h2>
</html>
IndexController.java class
package cn.laxi.jaxrs.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController {
@RequestMapping("/index")
public String index(){
return "index";
}
}
调度员-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<context:component-scan base-package="cz.laxi.org.controllers"></context:component-scan>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/defs/general.xml</value>
</list>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/>
</bean>
</beans>
pom.xml
<properties>
<org.springframework.version>4.3.3.RELEASE</org.springframework.version>
<apache.tiles>3.0.7</apache.tiles>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>${apache.tiles}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>${apache.tiles}</version>
</dependency>
web.xml
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
javabloggers
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
<servlet>
<servlet-name>Dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
<url-pattern>*.htm</url-pattern>
<url-pattern>*.json</url-pattern>
<url-pattern>*.xml</url-pattern>
</servlet-mapping>
</web-app>
为什么在视图中传递路径(正文和页脚)而不是 index.jsp 中的内容?
我的建议是在磁贴定义中的 : /WEB-INF.
前添加正斜杠,如下所示。
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="common" template="/WEB-INF/layouts/classic.jsp">
<put-attribute name="footer" value="/WEB-INF/layouts/footer.jsp" />
</definition>
<definition name="index" extends="common">
<put-attribute name="title" value="JAVA BLOG AGGREGATOR" />
<put-attribute name="body" value="/WEB-INF/jsp/index.jsp" />
</definition>
</tiles-definitions>
我正在使用 apache tiles 开发我的第一个 spring MVC 项目。但是,我对呈现的内容有疑问。
渲染路径 (WEB-INF/jsp/index.jsp) 而不是 index.jsp 中的内容(即来自 spring MVC 独有的 Hello)和页脚它呈现 (WEB-INF/layouts/footer.jsp) 而不是
© laxmon philip
请参阅我的输出的附加屏幕截图。 localhost:8080 output screenshot
这是我的第一个 spring MVC with apache tiles。请让我知道我在这里做错了什么。
我的tiles-定义如下
general.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="common" template="WEB-INF/layouts/classic.jsp">
<put-attribute name="footer" value="WEB-INF/layouts/footer.jsp" />
</definition>
<definition name="index" extends="common">
<put-attribute name="title" value="JAVA BLOG AGGREGATOR" />
<put-attribute name="body" value="WEB-INF/jsp/index.jsp" />
</definition>
</tiles-definitions>
classic.jsp 模板
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:getAsString name="title"/></title>
</head>
<body>
<tiles:insertAttribute name="body"/>
<br><br>
<center>
<tiles:insertAttribute name="footer"/>
</center>
</body>
</html>
footer.jsp模板
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
© laxmon philip
index.jsp 页
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<h2>Hello World From Spring MVC</h2>
</html>
IndexController.java class
package cn.laxi.jaxrs.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController {
@RequestMapping("/index")
public String index(){
return "index";
}
}
调度员-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<context:component-scan base-package="cz.laxi.org.controllers"></context:component-scan>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/defs/general.xml</value>
</list>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/>
</bean>
</beans>
pom.xml
<properties>
<org.springframework.version>4.3.3.RELEASE</org.springframework.version>
<apache.tiles>3.0.7</apache.tiles>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>${apache.tiles}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>${apache.tiles}</version>
</dependency>
web.xml
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> javabloggers index.html index.htm index.jsp default.html default.htm default.jsp
<servlet>
<servlet-name>Dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
<url-pattern>*.htm</url-pattern>
<url-pattern>*.json</url-pattern>
<url-pattern>*.xml</url-pattern>
</servlet-mapping>
</web-app>
为什么在视图中传递路径(正文和页脚)而不是 index.jsp 中的内容?
我的建议是在磁贴定义中的 : /WEB-INF.
前添加正斜杠,如下所示。
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="common" template="/WEB-INF/layouts/classic.jsp">
<put-attribute name="footer" value="/WEB-INF/layouts/footer.jsp" />
</definition>
<definition name="index" extends="common">
<put-attribute name="title" value="JAVA BLOG AGGREGATOR" />
<put-attribute name="body" value="/WEB-INF/jsp/index.jsp" />
</definition>
</tiles-definitions>