Declaration
Declares a variable or method valid in the scripting language used in the JSP page.
JSP Syntax
<%! declaration; [ declaration; ]+ ... %>
<jsp:declaration> code fragment [ declaration; ]+ ... </jsp:declaration
XML Syntax
<jsp:declaration> code fragment [ declaration; ]+ ... </jsp:declaration
Examples
<%! int i = 0; %> <%! int a, b, c; %> <%! Circle a = new Circle(2.0); %>
Description
A declaration declares one or more variables or methods that you can use in Java
code later in the JSP page. You must declare the variable or methodbefore you use it in the JSP page.
You can declare any number of variables or methods within one declaration element, as long as you end each declaration with a semicolon. The declaration must be valid in the Java programming language.
When you write a declaration in a JSP page, remember these rules:
- You must end the declaration with a semicolon (the same rule as for a Scriptlet, but the opposite of an Expression).
- You can already use variables or methods that are declared in packages imported by the page directive, without declaring them in a declaration element.
A declaration has translation unit scope, so it is valid in the JSP page and any of its static include files. A static include file becomes part of the source of the JSP page and is any file included with an include directive or a static resource included with a <jsp:include> element. The scope of a declaration does not include dynamic resources included with <jsp:include>.
