以servlet为例,配置web.xml的三种通配符配置方式
1.绝对通配符(精确匹配) /xx
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
访问方式: 根目录/xx
例:http://localhost:8080/Filecommons/test 可以访问
2.通配符配置方式* /xx/*
通过根目录加上设置的名字xx,后面不管跟什么都可以访问到
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/test/*</url-pattern>
</servlet-mapping>
访问方式: 根目录/xx/aa 根目录/xx/bb 根目录/xx/cc
重启服务器
http://localhost:8080/Filecommons/test 可以访问
http://localhost:8080/Filecommons/test/aa 可以访问
http://localhost:8080/Filecommons/test/sdff/dsf 可以访问
http://localhost:8080/Filecommons/test/rrrrtrt/huhb 可以访问
3.通配符配置方式 *.xx
根目录加上任意字符,最后只要有个.xx 就可以访问到
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
访问方式:根目录/aa/bb/c.xx 根目录/vv/ee/f.xx
重启服务器
http://localhost:8080/Filecommons/test 访问不到
http://localhost:8080/Filecommons/test.do 可以访问
http://localhost:8080/Filecommons/dsdsds/dfdfst.do 可以访问
http://localhost:8080/Filecommons/ggggg/ssss/tgpppt.do 可以访问