O'Reilly logo

Java Cookbook by Ian F. Darwin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

JSP Syntax Summary

Problem

You can’t remember all this post-HTML syntax.

Solution

Use the Table.

Discussion

Table 18-1 summarizes the syntax of JavaServer Pages. As the title implies, it contains only the basics; a more complete syntax can be downloaded from http://java.sun.com/products/jsp/.

Table 18-1. Basic JSP Syntax

Item

Syntax

Example

Scriptlet

<% code;%>
<% mountain.setHeight(1000); %>

Expression (to print)

<%= expr %>
<%= mountain.getHeight(  ) %>

Declaration

<%! decls; %>
<%! int height = 0; %>

Include

<jsp:include page="URL" flush=true />
<jsp:include page="./mountain-list.html" flush=true />

Forward

<jsp:forward page="url"/>
<jsp:forward page="./last-resort.html"/>

Use bean

<jsp:useBean .../>
<jsp:useBean class="x.ClimbBean" id="myClimbBean" scope="page"/>

Set property

<jsp:setProperty ... />
<jsp:setProperty name="myClimbBean" property="*" />

Page directive

<%@ page ... %>
<%@ page import="java.io.*" errorPage="catcher.jsp" %>

Comment

<!-- comment -->
<%!-- This comment appears in HTML -->

Hidden comment

<%-- comment --%>
<%-- This comment is local to JSP --%>

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required