I’m trying to have a JSP conditional that operates on the current URL. Basically I want to do something if the URL ends in /my-suffix, NOT including the query string etc. So I need to test against a substring of the url that’s right in the middle.
<c:if test="url not including query string+ ends with '/my-suffix'">
do something...
</c:if>
Is there a way to do this?
Checkout the JSTL functions taglib. One of the available functions is
fn:endsWith(). This allows you to for example do:(the
${pageContext.request.requestURI}returnsHttpServletRequest#getRequestURI()which does not include the query string)Or, if you’re already on a Servlet 3.0 compatible container which thus comes along with EL 2.2, such as Tomcat 7, Glassfish 3, etc, then you can also just invoke methods with arguments directly, such as
String#endsWith():