Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
234
Chapter 10 JSP Scripting Elements
Template Text
In many cases, a large percentage of your JSP page just consists of static
HTML, known as template text. In almost all respects, this HTML looks just
like normal HTML, follows all the same syntax rules, and is simply passed
through to the client by the servlet created to handle the page. Not only
does the HTML look normal, it can be created by whatever tools you already
are using for building Web pages. For example, I used Allaire's HomeSite for
most of the JSP pages in this book.
There are two minor exceptions to the template text is passed straight
through rule. First, if you want to have
<%
in the output, you need to put
<\%
in the template text. Second, if you want a comment to appear in the JSP
page but not in the resultant document, use
<% JSP Comment %>
HTML comments of the form
are passed through to the resultant HTML normally.
10.2 JSP Expressions
A JSP expression is used to insert values directly into the output. It has the
following form:
<%= Java Expression %>
The expression is evaluated, converted to a string, and inserted in the
page. This evaluation is performed at run time (when the page is requested)
and thus has full access to information about the request. For example, the
following shows the date/time that the page was requested:
Current time: <%= new java.util.Date() %>
Predefined Variables
To simplify these expressions, you can use a number of predefined variables.
These implicit objects are discussed in more detail in Section 10.5, but for
the purpose of expressions, the most important ones are:
request
, the
HttpServletRequest
response
, the
HttpServletResponse
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved