web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.apache.tiles.extras.complete.CompleteAutoloadTilesListener</listener-class>
</listener>
dispatcherServlet-xml
<mvc:annotation-driven/>
<context:annotation-config/>
<mvc:view-controller path="/"/>
<mvc:view-controller path="/contact.do"/>
<mvc:view-controller path="/hello.do"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
<property name="order" value="0" />
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
控制器类。
@RequestMapping(value = "/", method = RequestMethod.GET)
public String first(ModelMap model) {
System.out.println("Inside first method");
return "index";
}
@RequestMapping(value = "/addContact.do", method = RequestMethod.POST)
public String addContact(ModelMap model) {
System.out.println("Inside addContact method");
return "redirect:/contact.do";
}
@RequestMapping(value="/contact.do",method = RequestMethod.GET)
public String showContacts(ModelMap model) {
System.out.println("Inside showContacts method");
return "contact";
}
@RequestMapping("/hello.do")
public ModelAndView helloWorld(ModelMap model) {
String message = "Hello World, Spring MVC @ Javatpoint";
return new ModelAndView("hello", "message", message);
}
瓷砖.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="base.definition" template="/jsp/layout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="header" value="/jsp/header.jsp" />
<put-attribute name="menu" value="/jsp/menu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/jsp/footer.jsp" />
</definition>
<definition name="contact" extends="base.definition">
<put-attribute name="title" value="Contact Manager" />
<put-attribute name="body" value="/jsp/contact.jsp" />
</definition>
<definition name="hello" extends="base.definition">
<put-attribute name="title" value="Hello Spring MVC" />
<put-attribute name="body" value="/jsp/hello.jsp" />
</definition>
</tiles-definitions>
Appengine 错误日志
Uncaught exception from servlet
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tilesConfigurer' defined in ServletContext resource [/WEB-INF/SpringMVCtiles-servlet.xml]: Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError
Caused by: java.lang.ExceptionInInitializerError
at org.slf4j.LoggerFactory.reportMultipleBindingAmbiguity(LoggerFactory.java:260)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:140)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:121)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:332)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:284)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:305)
at org.apache.tiles.impl.BasicTilesContainer.<init>(BasicTilesContainer.java:71)
at org.apache.tiles.factory.BasicTilesContainerFactory.instantiateContainer(BasicTilesContainerFactory.java:107)
当从浏览器执行时,上述异常会给出 500 Server Error。尝试了以下建议,但仍然没有任何效果:1.为什么 Tiles 3.0.5 在 Spring web 4.1.5 上不起作用
2. 带有 Spring MVC 3 集成的 Tiles 3 不起作用
提前致谢。