My study on this field shown me that I can put ctx parameter in own EE filter in web.xml:
<filter>
<filter-name>ctxFilter</filter-name>
<filter-class>org.my.web.filter.CtxFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ctxFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
and:
public class CtxFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) { }
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setAttribute("CTX", request.getServletContext().getContextPath());
chain.doFilter(request, response);
}
@Override
public void destroy() { }
}
or in Spring interceptor (based on my project framework stack). Also this can be done by:
<spring:url value="/" var="ctx" htmlEncoding="true"/>
<a href="${ctx}/path/...">...</a>
or as:
<c:url value="/" var="ctx"/>
<a href="${ctx}/path/...">...</a>
but fist line of these examples must be duplicated across JSP files.
And finally you can implement TDL file with appropriate function WEB-INF/tlds/ctx.tld:
<function>
<name>ctx</name>
<function-class>org.my.web.Ctx</function-class>
<function-signature>java.lang.String getCtx()</function-signature>
</function>
Reference: