路径问题:
通过注解完成映射:
@webServlet("/LoginServlet")
通过这个路径访问指定的servlet,这个路径应该是工程名后的路径。
3.0版本才有这个注解,低版本需要在web.xml中写servlet和路径的映射关系。
tomcat有自己的查找机制,根据浏览器传的路径先在web目录下找,然后去src目录下寻找。
/* : 这个路径下的一起都能匹配。
页面请求路径两种书写方式,
绝对地址:
全路径,在浏览器中需要输入什么地址就得在action中写什么,一定是http://....
https 加密版http协议
全路径一定是/ 、 http://、https:// 开头。
/ 前默认带ip和端口。
相对地址:
相对于浏览器当前地址 参照物是URL。替换最后"/"后的东西
当前地址 http://localhost/home.html
访问地址 http://localhost/LoginServlet.html
./ 声明相对路径,当前路径。
- 例子1:
当前地址:http://localhost:8081/home.html
要访问地址:http://localhost:8081/LoginServlet
<form action="LoginServlet" method="post">
- 例子2:
当前地址:http://localhost:8081/home.html
要访问地址:http://localhost:8081/aa/LoginServlet
<form action="aa/LoginServlet" method="post">
- 例子3:
当前地址:http://localhost:8081/html/home.html
要访问地址:http://localhost:8081/LoginServlet
<form action="../LoginServlet" method="post">
网友评论