jsp 頁面如下:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Login</title> </head> <body> <form action = "/login" method="post"> username:<input name = "username" value = "username"> <br><br> password:<input type = "password" name = "password" value = "password"> <br><br> <input type = "submit" vlaue = "submit"> </form> </body> </html>
然后點擊提交之后,訪問的地址為http://localhost:8080/login
這個地址就沒有項目名http://localhost:8080/maventest_war_exploded/list.jsp
將action 前面“/”后去掉后如下:
--%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Login</title> </head> <body> <form action = "login" method="post"> username:<input name = "username" value = "username"> <br><br> password:<input type = "password" name = "password" value = "password"> <br><br> <input type = "submit" vlaue = "submit"> </form> </body> </html>
點擊提交后地址欄為://localhost:8080/maventest_war_exploded/login
總結
action 中:有斜杠訪問的是絕對地址,沒有斜杠訪問的相對地址
可參見:
https://blog.csdn.net/a1044909923/article/details/94738339