本文共 797 字,大约阅读时间需要 2 分钟。
在使用servlet的时候,我们必须配置web.xml 文件,下面是基本的配置,使用的时候,只需要将下面的内容,添加到web.xml文件中即可:
testservelet mypackage.servlet.QuickStartServlet testservelet /quickStartServlet
其中url-pattern的配置方式:
1)完全匹配 访问的资源与配置的资源完全相同才能访问到 2)目录匹配 格式:/虚拟的目录…/* *代表任意 如果使用这样的方式:那么下面的几种方式,都会出现同样的效果:http://localhost:8080/Testservlet01/aaa/bbb/ccc/quickStartServlethttp://localhost:8080/Testservlet01/aaa/bbb/ccc/http://localhost:8080/Testservlet01/aaa/bbb/ccc/dddhttp://localhost:8080/Testservlet01/aaa/bbb/ccc/eee.html
3)扩展名匹配 格式:*.扩展名
如果使用这样的方式:那么下面的几种方式,都会出现同样的效果:http://localhost:8080/Testservlet01/quickStartServlethttp://localhost:8080/Testservlet01/abchttp://localhost:8080/Testservlet01/
注意:第二种与第三种不要混用 /aaa/bbb/*.abcd(错误的)
转载地址:http://nxhbb.baihongyu.com/