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