3

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

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

Poppy
  • 2,902
  • 14
  • 51
  • 75

2 Answers2

11

You can just dynamically print the context path as follows:

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

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

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

You can use ../ or use context path as follows

<form action="/<%=request.getContextPath()%>/alterPassword" id="changepassword" method="post"
        autocomplete="off" onsubmit="return checkPassword();">
adarshr
  • 61,315
  • 23
  • 138
  • 167