springmvc-servlet.xml文件配置,方法二

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

    <!--
        springmvc的核心servlet
        第一种:[servlet-name]-servlet.xml,比如:springmvc-servlet.xml,注意名字是固定的
        第二种:改变命名空间(推荐使用)
        第一种和第二种都必须把配置文件放置在web-inf目录下。

        第三种:通过contextConfigLocation
        可以放置在任意地方
    -->
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!--注意这里使用了第二种方法,改变命名空间-->
        <init-param>
            <param-name>namespace</param-name>
            <param-value>haomvc</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

在这里插入图片描述
注意haomvc.xml还是要放在WEB-INF目录下,只有方法三可以改变位置

猜你喜欢

转载自blog.csdn.net/qq1641725218/article/details/83098175