Use relative path for form actions in JSP

11,418

Solution 1

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:

Solution 2

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

<form action="/<%=request.getContextPath()%>/alterPassword" id="changepassword" method="post"
        autocomplete="off" onsubmit="return checkPassword();">
Share:
11,418
Poppy
Author by

Poppy

Passionate about programming. Good at java, jquery and little bit of .net. Working as a developer in MNC

Updated on June 04, 2022

Comments

  • Poppy
    Poppy almost 2 years

    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 ?

  • Chen Ni
    Chen Ni almost 4 years
    Thank you so much! After trying out a lot of different things this finally worked for me.