在JSP中使用相对路径进行表单操作 [英] Use relative path for form actions in JSP

查看:79
本文介绍了在JSP中使用相对路径进行表单操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在表单操作中使用相对路径

How to use relative path in form action

<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;">

在上面的代码中,有什么方法可以使用相对路径代替myapp/alterPassword吗?

In the above code is there any way to use relative path instead of the myapp/alterPassword ?

推荐答案

您可以按如下所示动态打印上下文路径:

You can just dynamically print the context path as follows:

<form action="${pageContext.request.contextPath}/alterPassword" ...>

或使用HTML <base>标记,以使页面中的所有相对链接都相对于它.

Or use the HTML <base> tag so that all relative links in the page are relative to it.

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆