如何在表单操作中使用相对路径
<form action="/myapp/alterPassword" id="changepassword" method="post"
autocomplete="off" onsubmit="return checkPassword();">
<div
style="display: block; position: absolute; top: 15%; left: 35%; width: 480px;">
Run Code Online (Sandbox Code Playgroud)
在上面的代码中有没有办法使用相对路径而不是myapp/alterPassword?
您可以按如下方式动态打印上下文路径:
<form action="${pageContext.request.contextPath}/alterPassword" ...>
Run Code Online (Sandbox Code Playgroud)
或者使用HTML <base>标记,以便页面中的所有相对链接都相对于它.