表单提交,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

原文地址:https://www.cnblogs.com/helloqiufei/p/11655309.html