iTP Secure WebServer System Administrator's Guide (iTPWebSvr 5.1+)
Using NonStop Servlets for JavaServer Pages With
The iTP Secure WebServer
iTP Secure WebServer System Administrator’s Guide—522659-001
9-36
JSP Syntax Basics
Example code for a simple JSP include directive is shown in An Example of JSP Code
on page 9-36. You will see that JSP is a lot easier to code than directly coding the
servlets in native Java, as shown above.
JSP Syntax Basics
There are two main classifications of syntax: directives and scripting elements such as
declarations, expressions and scriptlets.
Directives
The Page Directive. This directive is a JSP tag that you will use in almost every JSP
source file you write. The page directive gives instructions to the JSP container that
apply to the entire JSP source file. For example, comments that will become part of the
compiled JSP file or the scripting language used in the JSP source file, packages the
source file would import, or the error page called if an error or exception occurs.
The Include Directive. This inserts the contents of another file in the main JSP file,
where the directive is located. You can use it for including copyright information,
scripting language files, or anything you might want to reuse in other applications. The
include directive allows you to separate your content into more manageable elements
such as including a common page header or footer. The page included can be a static
HTML page or more JSP content.
Scripting Elements
Declarations. With declarations you can define methods or variables in a JSP page that
will be accessible to other code within the same page.
Expressions. Expressions are simple JSP tags that convert the value of an expression
defined between <%= %> into a string and emits that value as dynamically generated
text. As such they are shortcuts for generating text so that you do not have to call the
println ( ) method to display text.
Scriptlets. You may write java code anywhere in a JSP page, in the form <% code %>.
By using the import attribute of the page directive you have access to all Java APIs from
within your scriptlet code.
An Example of JSP Code
This is an example use of templating, a common technique used in web page
development, that uses the services of more than one servlet. We show the template
coded as JSP using the include directive to reference some HTML in another file.
The JSP is:
<%-- Filename: "TemplateDemo.jsp" --%>
<HTML>
<BODY>
<CENTER> Welcome To My WebSite</CENTER>
<BR>
<P> The time is <% new java.util.Date().toString() %> </P>
<%@ include file = "Body.html" %>