Search code examples
javajspscriptlet

How to get to application context path without using scriplets in JSP files?


So I have a code like this in my jsp file:

<a href="<%= getServletConfig().getServletContext().getContextPath() %>/registerMe.jsp"
               class="btn">Not a member? Register..</a>

And I know that using scriplets is bad practice in JSP files. How can I avoid such a situation then?


Solution

  • Use an EL expression:

    <a href="${pageContext.servletContext.contextPath}/registerMe.jsp"
               class="btn">Not a member? Register..</a>