Making an XML-compliant JSP: a JSP Document

This topic didn’t fit well anywhere else, so we decided to stick it in this chapter since we’re talking about XML so much. The exam doesn’t require you to be an XML expert, but you do have to know two things: the syntax for the key DD elements, and the basics of making what’s known as a JSP Document. (“As opposed to what? If a normal JSP isn’t a document, what is it?” That’s what you’re asking, right? Think of it this way—a normal JSP is a page, unless it’s written with the XML alternatives to normal JSP syntax, in which case it becomes a document.)

All it means is that there are really two types of syntax you can use to make a JSP. The text in grey is the same across both types of syntax.

 

Normal JSP page syntax

JSP document syntax

Directives (except taglib)

<%@ page import="java.util.*" %>

<jsp:directive.page import="java.util.*"/>

Declaration

<%! int y = 3; %>

<jsp:declaration>
    int y = 3;
</jsp:declaration>

Scriptlet

<% list.add("Fred"); %>

<jsp:scriptlet>
    list.add("Fred");
</jsp:scriptlet>

Text

There is no spoon.

<jsp:text>
    There is no spoon.
</jsp:text>

Scripting Expression

<%= it.next() %>

<jsp:expression>
    it.next()
</jsp:expression>

Relax

This is all the exam covers on JSP Documents.

We aren’t going to say any more about it because writing XML-compliant JSP documents is probably not something you’ll do. The XML syntax is used mainly by tools, and the table above just shows you how the tool would transform your normal JSP syntax into an XML document. ...

Get Head First Servlets and JSP, 2nd Edition 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.