java servlet url-pattern路径配置

今天要做一个http模拟,写个servlet做路径配置时,忘记几种配置方式的含义,在此记录一下含义以及我的错误配置方式。

........

web.xml片段

.....

错误的配置:<url-pattern> /hello/*.html<url-pattern>路径和扩展混合到一起使用时,容器无法判断该使用什么规则匹配url请求。

错误信息:Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> /hello/*.html in servlet mapping

正确的配置一:<url-pattern>*.html</url-pattern>,只处理以(.html)结尾的urI请求(后缀式)

                 二:<url-pattern>/hello/*</url-pattern>,只处理<webroot>/hello/******这样的url请求(路径式)

                 三:<url-pattern>/</url-pattern>,(不考虑优先级问题)处理所有的<webroot>/****这样的url请求(默认式)

                 四:<url-pattern>/demo/hello.html</url-pattern>,只处理一个和配置相同请求

a)/hello/welcome/*

b)/hello/welcome.htmlc)/hello/*

参考如下博客

http://01121264-163-com.iteye.com/blog/1530063

http://blog.csdn.net/xiaxiaorui2003/article/details/7295558

你可能感兴趣的:(java servlet url-pattern路径配置)