How to get the current context path in a JSP file

Most of the times when you want to place a link somewhere in you web application you want it to be relative to the context path (the root path under which your application is available).  This way, no matter where you navigate in your application, the link will always point to the same page.

In a JSP page you can use the following EL expression to get the context path:

${pageContext.request.contextPath}

For exmaple, if my context path is /jtuts and I want to set the action of a form to point to /jtuts/register then I would be able to do it the following way:

<form:form commandName="userForm" action="${pageContext.request.contextPath}/register" method="post">
    <!-- Contents skipped for brevity. -->
</form:form>