We use the tomcat urlrewrite plugin to rewrite outbound URLs as well as inbound ones. To do this, you need to use the JSTL tag.
This works great for clean urls and i18n, however it yields ugly code, including tags-within-tags, like this:
<link href='<c:url value="/content/bootstrap/css/bootstrap.css" />' rel="stylesheet" />
or:
<a href='<c:url value="/nextPage.jsp"/>' />Next Page</a>
One alternative is to use a variable, like this:
<c:url value="/nextPage.jsp" var="nextPageUrl"/>
<a href='${nextPageUrl}' />Next Page</a>
This is really clean, but verbose.
Is there an expression-language friendly way to do this?
I was sort of hoping for something like:
<a href='${url "/nextPage.jsp}' />Next Page</a>
Thanks.
The solution I finally came up with was to use custom tags to solve the problem for CSS and JS. A similar solution could be applied to tags too of course, although I haven’t had the need yet.
The CSS tag looks like this, the Javascript one is obviously very similar:
Don’t forget to import the tags in your jsp:
The custom EL solution would be cleaner is some circumstances, but if you want to add support for additional parameters or attributes, a tag is probably the way to go.