Is there a library or best-practice way of creating a menu with navigation links using JSTL?
I have 5 links that go on every page. I want the link that points to the current page to be “disabled”. I can do this manually but this must be a problem that people have tackled before. I wouldn’t be surprised if there is a taglib that handles it but I don’t know of it.
You can let JSTL/EL generate HTML/CSS conditionally based on the URL of the requested JSP page. You can get it by
${pageContext.request.servletPath}in EL. Assuming that you have the links in someMap<String, String>in the application scope:Or when you’re just after a CSS class
You can use
<jsp:include>to reuse content in JSP pages. Put the above in its ownmenu.jspfile and include it as follows:The page is placed in
WEB-INFfolder to prevent direct access.