Chris Greenhalgh, 2007-01-30
This document gives some general pointers and suggestions on use of
JSP for dynamic HTML generation (no EQUIP2).
See EQUIP2_WebApp_Dynamic_Pages_using_EQUIP2_Taglib.html for
EQUIP2-specific JSP information.
Tomcat 5.5 supports Servlet 2.4 (JSR 154) & JSP 2.0 (JSR 152).
JSP 2.0 supports:Actions available include:
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>The most immediately useful tag is
<spring:bind path="BEAN.PROPERTY"> ... ${status.value} ... </spring:bind>which binds the value of the named property of the named (Spring/request scope) bean to the page variable status within the scope of the tag. These are useful with Spring's own form support, to guide its population of backing objects. See EQUIP2_WebApp_Form_Handling.html
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
Refer to the JSTL 1.1 specification (or similar) for complete
documentation.
Some example JSPs are present in WEB-INF/jsp/simplerequest/view/...
use of jsp:include tag:
<jsp:include page="included.jsp">
<jsp:param name="parameter" value="foo"/>
</jsp:include>
scriptlets (tag are preferred!). E.g.:
<%= 3+4 %>
<%= new java.util.Random().nextInt() %>
<% int x=4; %>
<%= x %>
<% for (int i=0; i<10; i++) { %>
<%-- ... --%>
<% } %>
<%-- declare taglibs --%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%-- unlike XSLT there are mutable variables --%>
<c:set var="x" value="6"/>
<c:out value="${x}"/>
<%-- simple condition --%>
<c:if test="${x==6}">
<%-- ... --%>
</c:if>
<%-- multi-case condition c.f. switch --%>
<c:choose>
<c:when test="${x==5}">Aha!</c:when>
<c:otherwise>No aha...</c:otherwise>
</c:choose>
<%-- simple loop (use c:forItems to enumerate list/array --%>
<c:set var="names" value="a,b,c,d,e"/>
<c:forTokens var="name" items="${names}" delims=",">
<p>name = <c:out value="${name}"/></p>
</c:forTokens>
Note that values in the 'model' returned from a Spring controller
are passed in the request, which is accessed from JSP EL as (e.g. the 'arg' property of the object
called 'command' in the
returned model):
<c:out value="${requestScope.command.arg}"/>