web.xml入门级详解

<!-- xml版本,编码方式 -->
<?xml version="1.0" encoding="UTF-8"?> 
<!-- web-app标签;xmlns:命名空间;用xsi代表长长的链接;xsi:schemaLocation=需要使用的命名空间 供命名空间使用的 XML schema 的位置-->
<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_3_1.xsd"
         version="3.1">

    <!-- 区分项目名称,防止默认重名 -->
    <context-param><!-- 设置初始化参数 -->
        <param-name>webAppRootKey</param-name>
        <param-value>empty-spring-web</param-value>
    </context-param>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <context-param>
        <param-name>logVerbosityLevel</param-name>
        <param-value>DEBUG</param-value>
    </context-param>
    <context-param>
        <param-name>defaultHtmlEscape</param-name>
        <param-value>true</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
    </listener><!-- 设置WebAppRootListener监听器:监听web.xml中的配置para-name为webAppRootKey的值 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener><!-- 设置ContextLoaderListener监听器:启动Web容器时,自动装配ApplicationContext的配置信息 -->

    <!-- 字符集 过滤器  -->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name><!-- 编码拦截器,此处相当于申明一个变量,后面mapping-->
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param><!-- 定义filter参数赋值 -->
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value><!-- 为true表明在html页面或表单中设置编码是没有用的,即这儿的编码格式是固定的 -->
        </init-param>
    </filter>
    <filter-mapping><!-- 定义filter拦截的URL -->
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern><!-- filter 负责拦截的URL -->
    </filter-mapping>

    <!-- Spring view分发器 -->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param><!-- 定制servlet初始化参数 -->
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext-mvc.xml</param-value>
        </init-param>
        <init-param>
            <param-name>dispatchOptionsRequest</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup><!-- 标记容器是否在启动的时候就加载这个servlet(实例化并调用其init()方法);当值为0或大于0时表示启动 -->
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern><!-- 浏览器访问的地址 -->
    </servlet-mapping>

    <welcome-file-list><!-- 指定欢迎页面 -->
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <error-page><!-- 指定错误处理页面 -->
        <error-code>404</error-code>
        <location>/error/404.html</location>
    </error-page>
</web-app>

关于web.xml入门级解释尽在于此,若有不足,请补充


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值