ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Web Server Java -- Servlets and JSP
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11

JSP Syntax Summary

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

Use the Table.


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





<% ;%>

<% mountain.setHeight(1000); %>

Expression (to print)

<%= expr %>

<%= mountain.getHeight( ) %>


<%! decls; %>

<%! int height = 0; %>


<jsp:include page="URL" flush=true />

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


<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 -->

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

Hidden comment

<%-- comment --%>

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

Program: CookieCutter

CookieCutter is a little program I wrote that allows you to display, modify, and even delete cookies. Since the banner-ad-tracking firm DoubleClick probably keeps a lot of information on your browsing habits, you want to befuddle them. After all, they are using a tiny bit of storage on your hard disk to rack up per-click profits, giving you nothing in return (directly, at least; obviously, ad sponsorship keeps some web sites on the air). In Figure 18-10, I am editing the cookie to, umm, "update" the personal identity cookie to an invalid number (a lot of 9's, and too many digits). A few lines above that, you can see the prefs.bgcolor cookie that I set to "green."

Screen shot.
Figure 18-10. The CookieCutter display

I won't show the CookieCutter source code here as it doesn't really relate to web techniques (it's a client-side application), but it's included in the source archive for the book. CookieCutter also assumes your cookies are stored in the Netscape format; for the Microsoft Explorer format, you'll have to change the file-reading and file-writing code.

Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11

Next Pagearrow