InfoCenter Home > 4.2.2.3.3: JSP syntax: Inline Java code (scriptlets)You can embed any valid Java language code inline between the <% and %> tags. Such embedded code is called a scriptlet. If you do not specify the method directive, the generated code becomes the body of the service method. The scriptlet can use a set of predefined variables that correspond to essential servlet, output, and input classes:
An example: <% foo = request.getParameter("Name"); out.println(foo); %> Be sure to use the braces characters, { }, to enclose if, while, and for statements even if the scope contains a single statement. You can enclose the entire statement with a single scriptlet tag. However, if you use multiple scriptlet tags with the statement, be sure to place the opening brace character, {, in the same statement as the if, while, or for keyword. The following examples illustrate these points. The first example is the easiest. <% for (int i = 0; i < 1; i++) { out.println("<P>This is written when " + i + " is < 1</P>"); } %> ... <% for (int i = 0; i < 1; i++) { %> <% out.println("<P>This is written when " + i + " is < 1</P>"); %> <% } %> ... <% for (int i = 0; i < 1; i++) { %> <% out.println("<P>This is written when " + i + " is < 1</P>"); %> <% } %>
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|