码迷,mamicode.com
首页 > 编程语言 > 详细

Spring MVC URL配置问题

时间:2014-09-22 14:38:53      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   os   ar   sp   art   问题   on   

最近因为手误,两次遇到 访问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配置问题

标签:blog   http   io   os   ar   sp   art   问题   on   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!