Java Reference
In-Depth Information
In line 29, the form is being submitted to the URL of the page. Because pages are actu-
ally servlets, they can also receive form data that's sent by post or get .
This page uses the store field to hold “Amazon” if Amazon.com is the preferred store
and “BN” if Barnes & Noble is the preferred store.
One thing to note as you test the page is how the radio buttons on the form always match
the store you've chosen. This occurs because of expressions that appear on lines 29 and
31. Here's one of those expressions:
<%= (store.equals(“Amazon”) ? “ checked” : “”) %>
This expression uses the ternary operator with the conditional store.equals(“Amazon”) .
If this condition is true, the word “checked” is the value of the expression. Otherwise, an
empty string ( “” ) is the value.
The value of expressions is displayed as part of the JSP page. Figure 21.6 shows what
this page looks like in a web browser.
FIGURE 21.6
Displaying dynamic
content using
scriptlets.
Using Declarations
Another element you can insert into a JSP page is a declaration , which is a statement
that sets up a variable or method that will be defined in the page when it's compiled into
a servlet. This feature is primarily used in conjunction with expressions and servlets.
Declarations are surrounded by <%! and %> tags, as in the following example:
<!% boolean noCookie = true %>
<!% String userName = “New user” %>
Search WWH ::




Custom Search