This repository was archived by the owner on Nov 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Java, JSP, JSTL, EL, Tomcat notes and tips
Michael Hulse edited this page Aug 2, 2017
·
8 revisions
- Create a file called
global.jsp(for example). - Add your
taglibcalls and other important code:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="page" scope="session" value="${fn:split(fn:split(pageContext.request.servletPath, '.')[0], '/')[0]}" />- Put this at the top of every include file you need the
taglibs and/or variables:
<%@ include file="/includes/global.jsp" %>Now you can use EL (Expression Language) and/or <c:xxx> tags on your templates.
<%-- … something here … --%>Static includes (compile time):
<%@ include file="path/to/file.jsp" %>Dynamic includes (execution time):
<jsp:include page="path/to/file.jsp" />
<c:import url="http://www.example.com/foo/bar.html" />Passing params to jsp:include:
<jsp:include page="includes/top.jsp">
<jsp:param name="title" value="Detective Activity" />
</jsp:include> <%--
<c:set var="s" value="${request.getHeader('referer')}" />
<%out.println(request.getHeader("referer"));%>
(${s})
${fn:contains(s, 'support-team.jsp')}
if(request.getHeader("referer").indexOf("support-team.jsp") != -1)
--%>
${header.referer}, ${header['referer']}, ${param.from}, ${param['from']}
<c:if test="${param.from == 'support-team'}">
<a href="#" class="close-ish" onclick="history.go(-1);return false;">Close</a>
</c:if>
${header.referer}
<c:if test="${fn:contains(header.referer, 'support-team.jsp')}">
<a href="#" class="close-ish" onclick="history.go(-1);return false;">Close</a>
</c:if>This looks like lots of great tips: http://stackoverflow.com/questions/1296235/jsp-tricks-to-make-templating-easier