表單提交,action 地址問題


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM