路径映射
指定一个映射路径
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
指定多个映射路径
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/hello2</url-pattern>
</servlet-mapping>
...
指定通用映射路径
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/hello/*</url-pattern>
</servlet-mapping>
默认请求路径
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
指定一些后缀或者前缀
<!-- xxx.do -->
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
优先级问题
指定了固有的映射路径优先级最高,如果找不到就会走默认的处理请求;
<servlet-mapping>
<servlet-name>error</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<!-- 404 -->
<servlet-mapping>
<servlet-name>error</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
过滤器配置
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>com.demo.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern> <!--所有请求过滤-->
</filter-mapping>
监听器配置
<listener>
<listener-class>com.demo.listener.CountOnlineListener</listener-class>
</listener>
session配置
<session-config>
<!--15分钟后自动失效-->
<session-timeout>15</session-timeout>
</session-config>
初始化参数
<context-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</context-param>
欢迎页
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>