JSP Elements

There are three types of JSP elements: directive, action, and scripting. A new construct added in JSP 2.0 is the Expression Language (EL) expression; let’s call it a fourth element type, even though it’s a bit different than the other three. Example 4-3 shows a simple JSP page with most of these element types.

Example 4-3. JSP page showing a dynamically calculated sum
                  <%@ page contentType="text/html" %>
                  <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
  <head>
    <title>JSP is Easy</title>
  </head>
  <body bgcolor="white">
  
    <h1>JSP is as easy as ...</h1>
  
    <%-- Calculate the sum of 1 + 2 + 3 dynamically --%>
    1 + 2 + 3 = <c:out value="${1 + 2 + 3}" />
  
                      <jsp:include page="footer.jsp" />
  </body>
</html>

The page in Example 4-3 displays static HTML plus the sum of 1, 2, and 3, calculated at runtime and dynamically added to the response. It also includes the output produced by another page, footer.jsp, in the response. The result of processing the page is shown in Figure 4-9.

Sample JSP page output
Figure 4-9. Sample JSP page output

Directive elements

The directive elements you can use in a JSP page, shown in Table 4-1, specify information about the page itself that remains the same between requests—for example, if session tracking is required, buffering requirements, and the name of a page that should be used to report errors, if any. Directives are also used to build a complete page ...

Get JavaServer Faces now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.