Java Reference
In-Depth Information
The following step enters the code to use session data in a JSP scriptlet.
To Use Session Data in a JSP Scriptlet
1. Enter lines 41 through 59 as shown in Figure 12-65 on page 841.
TextPad displays the JavaScript function, checkUses(), in the coding window
(Figure 12-69). JSP tags surround the Java scriptlet code that obtains the
session attribute, uses. The alert() function uses a string expression
surrounded by JSP tags.
alert() built-in
function
JSP tags
checkUses()
JavaScript
function
JSP tags
JSP string tags
FIGURE 12-69
Recall that the onLoad() event handler executes when the page is loaded by
the browser. In line 59, this event handler calls the checkUses() method when the
form is loaded.
Using a JSP Page Directive
Because a JSP contains Java code, you will need to be able to import classes,
either from the SDK or from other packages, for use in any of the Java code in
the JSP. A JSP page directive sets conditions that apply to the entire JSP file, not
just a single section of JSP code. Figure 12-70 on the next page displays lines 60
through 151 of the code for mainForm.jsp. A page directive is displayed on line
60, using the import attribute to import the java.util package of classes. Note
that an assignment operator is used, unlike in a Java program. If multiple classes
are imported, all imported classes are listed within the double quotes and sepa-
rated by commas. An alternative is to use multiple JSP page directives.
 
Search WWH ::




Custom Search