url-parttern里的值是对url起别名。
在本例中,我们打开tomcat,在%tomcat_home%webapps/root/下创建hello.html,代码如图:
路径如图:
运行tomcat,在浏览器里输入 http://localhost:8080/hello.html,可以看到如下页面:
输入这些后,点击提交:
可以发现,网址是:http://localhost:8080/TomcatTestqwead/HelloForm?name=asdfasdf&url=sdfasdf。
扫描二维码关注公众号,回复:
52741 查看本文章
我们现在可以总结:当我们点击提交按钮时,会把form标签里的action给串接到url后面。在本例里,hello.html的url是:http://localhost:8080/hello.html,提交后的url是:http://localhost:8080/TomcatTestqwead/HelloForm?name=asdfasdf&url=sdfasdf。
其中,TomcatTestqwead/HelloForm是action的属性值。?是间隔符,name=asdfasdf&url=sdfasdf是属性名以及属性值。而web.xml正是通过与action的属性值相同url-pattern来找到与url-pattern有相同servlet-name的servlet标签,在找到里面的servlet-class的类,运行这个类。