Elements of JSP Pages
An earlier section of this appendix described some general characteristics of JSP pages. This section discusses in more detail the kinds of constructs you can use.
JSP pages are templates that contain static parts and dynamic parts:
Literal text in a JSP page that is not enclosed within special markers is static; it’s sent to the client without change. The JSP examples in this book produce HTML pages, so the static parts of JSP scripts are written in HTML. But you can also write pages that produce other forms of output, such as plain text, XML, or WML.
The nonstatic (dynamic) parts of JSP pages consist of code to be evaluated. You distinguish code from static text by enclosing it within special markers. Some markers indicate page-processing directives or scriptlets. A directive gives the JSP engine information about how to process the page, whereas a scriptlet is a mini-program that is evaluated and replaced by whatever output it produces. Other markers take the form of tags written as XML elements; they are associated with classes that act as tag handlers to perform the desired actions.
The following sections discuss the various types of dynamic elements that JSP pages can contain.
Scripting Elements
Several sets of scripting markers allow you to embed Java code or comments in a JSP page:
<%
...%>
The
<%
and%>
markers indicate a scriptlet—that is, embedded Java code. The following scriptlet invokesprint()
to write a value to the output page:<% out.print (1+2); ...
Get MySQL Cookbook, 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.