Spring和Tiles3:无法解析名为'dispatcher'的servlet中带名称的视图

时间:2016-11-15 12:52:06

标签: spring spring-mvc tiles tiles-3

我是Tiles和Spring MVC的新手。这是一个简单的例子,但是2小时后我还没弄清楚它有什么问题。

这是我的/WEB-INF/dispatcher-servlet.xml

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />

    <context:component-scan base-package="gm.*"/>
    <mvc:annotation-driven/>

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="index.html">indexController</prop>
            </props>
        </property>
    </bean>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" >
            <value>org.springframework.web.servlet.view.tiles3.TilesView</value>
        </property>
    </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>

    <bean name="indexController"
        class="org.springframework.web.servlet.mvc.ParameterizableViewController"
        p:viewName="index" />  

我的/WEB-INF/web.xml

<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>
</servlet-mapping>

<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

<welcome-file-list>
    <welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>

我的/WEB-INF/tiles.xml

<tiles-definitions>
<definition name="home.index" template="/WEB-INF/jsp/templates/templateUser.jsp">
    <put-attribute name="content" value="/WEB-INF/jsp/home/index.jsp"></put-attribute>
</definition>   
</tiles-definitions>

我的控制器

package gm.controller;

@Controller
@RequestMapping("/home")
public class Home {

@RequestMapping(method = RequestMethod.GET)
public String index(ModelMap modelMap){
    return "home.index";
}
}

我将index.jsp放在/WEB-INF/jsp/home/index.jsp

当我访问此网址http://localhost:8080/myproject/home.html时,它会一直说出标题中的错误。

知道怎么解决吗?

0 个答案:

没有答案