我爱编程

web.xml详解

2017-05-23  本文已影响37人  MVBin

filter配置多个url-pattern的正确方式

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.jsp</url-pattern>
</filter-mapping>

classpath与classpath*的区别

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:/spring/*.xml</param-value>
</context-param>

这种classpath配置是指只加载本地classpath路径下的spring文件夹中的以.xml结尾的文件。

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:/spring/*.xml</param-value>
</context-param>

这种classpath*配置是指不仅加载本地classpath路径下的,而且也加载jar文件下的classpath路径下的spring文件夹中的以.xml结尾的文件。

配置load-on-startup的作用

在web.xml中配置servlet时有时需要配置load-on-startup这个属性,其作用是指在web容器启动时是否就加载该servlet,其值需为整数。当<load-on-startup></load-on-startup>中的值大于等于0时,表示在容器启动时就加载,值越小,加载优先级越高;当小于0或者没有值时,表示在用到此servlet时才加载,不在启动时加载。

上一篇 下一篇

猜你喜欢

热点阅读