Scripting elements let you add small pieces of code in JSP page,such as an if statement.The scripting code must be written in the language defined by the page directive.
一、Declaration
Declarations are used to declare scripting language variables or methods.
Syntax
<%! declaration %>
Example
<%! int globalCounter = 0; %>
二、Expression
An expression is used to add the result of executing a scripting expression to the response. The content between the start and the end characters must be a complete valid expression in the language defined by the page directive that results in a string or can be converted to a string. All JSP implicit scripting variables are visible in an expression element.
Syntax 1: In a regular JSP page
<%= expression %>
Example
<%= globalCounter++ %>
三、Scriptlet
Scriptlets are used to embed scripting code fragments in a page. The content must be a code fragment in the language defined by the page directive.
Syntax
<% scripting code fragment %>
Example
<% java.util Date clock = new java.util.Date( ) %>
<% if (clock.getHours( ) < 12) { %>
Good morning!
<% } else if (clock.getHours( ) < 17) { %>
Good day!
<% } else { %>
Good evening!
<% } %>
阅读(588) | 评论(0) | 转发(0) |