Servlet配置
1.配置Serlvet加载时机
2.配置多映射
配置加载时机
新建项目config->创建包com.xiaoan.config->创建类FirstServlet implements Servlet(实现Servlet接口)
->创建类SoundServlet(也实现Servlet接口)
配置web.xml
先配置两个Servlet实现类的Servlet
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 config
4
5
6 fs
7 com.xiaoan.config.FirstServlet
8 3
9
10
11
12 fs
13 /fs
14
15
16
17
18 ss
19 com.xiaoan.config.SoundServlet
20 1
21
22
23 ss
24 /ss
25
26
27
运行项目控制台输出为
Sound constiuctor
Sound init
First constiuctor
first init
说明 配置值越小 越会先加载
Servlet多映射
将上面的web.xml的fs servlet的配置中再添加一个servlet-mapping
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 config
4
5
6 fs
7 com.xiaoan.config.FirstServlet
8 3
9
10
11
12 fs
13 /fs
14
15
16 fs
17 /fs1/*
18
19
20 fs
21 *.html
22
23
24
25
26 ss
27 com.xiaoan.config.SoundServlet
28 1
29
30
31 ss
32 /ss
33
34
35
重启服务器
届时 浏览器中访问
localhost:8080/config
http://localhost:8080/config/fs
http://localhost:8080/config/fs1
http://localhost:8080/config/fs1/任意字符
http://localhost:8080/config/任意字符.html
会运行firstservlet的 service方法
原文:http://www.cnblogs.com/azhw/p/5676926.html