Java Reference
In-Depth Information
System.out.println( ) will output to the console, which is useful for debugging
purposes, while out.println( ) will output to the browser. The following scriptlet
invokes the incrementCount( ) method and then outputs the value in count :
<%
out.println("The counter's value is " + count + "<br />");
incrementCount();
%>
Display 19.20 is a JSP page with a declaration, expression, and scriptlet that outputs
text inside a header tag from levels 1 to 6. The identifier LASTLEVEL is declared as the
last heading level that is to be displayed. LASTLEVEL is modified by static final ,
because it is intended as a constant. A loop inside the scriptlet outputs sample text for
each level. The HTML that is generated by the JSP page is shown in Display 19.21,
and the browser view is shown in Display 19.22.
Display 19.20
JSP Code to Display Heading Levels
1 <html>
2 <title>
3 Displaying Heading Tags with JSP
4 </title>
5 <body>
6 <%!
7 private static final int LASTLEVEL = 6;
8 %>
JSP declaration.
9 <p>
10 This page uses JSP to display Heading Tags from
11 Level 1 to Level <%= LASTLEVEL %>
12 </p>
JSP expression that evaluates
to the value 6.
JSP scriptlet that contains
a block of Java code.
13 <%
14 int i;
15 for (i = 1; i <= LASTLEVEL; i++)
16 {
17 out.println("<H" + i + ">" +
18 "This text is in Heading Level " + i +
19 "</H" + i + ">");
20 }
21 %>
22 </body>
23 </html>
 
 
Search WWH ::




Custom Search