首页 > 编程语言 > 详细

Spring MVC URL配置问题

时间:2014-09-22 13:46:44      阅读:264      评论:0      收藏:0      [点我收藏+]

最近因为手误,两次遇到 访问Spring MVC 程序时不能正确解析JSP,返回类型是text/plain,后来终于发现问题的原因:

下面是web.xml中的 Dispatcher Servlet 配置,注意 <url-pattern>的配置

<!--spring mvc 这种方法不能正确访问,返回类型是text/plain-->
    <servlet>
        <servlet-name>Dispatcher Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath:spring-mvc-config.xml
            </param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Dispatcher Servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
<!--spring mvc 这种方法可以正确访问,返回类型是text/html-->
    <servlet>
        <servlet-name>Dispatcher Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath:spring-mvc-config.xml
            </param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Dispatcher Servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>


参与这两个位置:

http://my.oschina.net/ayesd/blog/278336

http://www.cnblogs.com/fangjian0423/p/servletContainer-tomcat-urlPattern.html#springmvc





Spring MVC URL配置问题

原文:http://my.oschina.net/thinker4self/blog/316741

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!