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,692
  • 12
  • 47
  • 70

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,040,783
  • 362
  • 3,548
  • 3,513
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
  • 59,379
  • 22
  • 134
  • 163