BBS水木清华站∶精华区

发信人: agents (智能代理), 信区: Java        
标  题: JSP语法(3) 
发信站: BBS 水木清华站 (Tue Jan  2 14:46:05 2001) 
 
3 【Declaration】   
Declares a variable or method valid in the scripting language used in the page. 
 
▲[JSP Syntax] 
 
<%! declarations %> 
 
▲ [Examples] 
 
<%! int i = 0; %> 
<%! int a, b, c; %> 
<%! Circle a = new Circle(2.0); %> 
 
▲ [Description] 
 
A declaration declares one or more variables or methods for use later in  
the JSP source file. 
A declaration must contain at least one complete declarative statement.  
You can declare any number of variables or methods within one declaration tag,  
as long as they are separated by semicolons. The declaration must be valid in 
 the scripting language used in the JSP file. In JSP 1.0, you must use the  
JavaTM programming language for scripting, and declarations must conform to  
the Java Language Specification. 
 
When you use the Java programming language for scripting, remember these  
rules: 
(1) You must end the declaration with a semicolon (the same rule as for   a  
Scriptlet, but the opposite of an Expression). 
(2) You must declare the variable or method before you use it in the JSP file. 
(3) You can already use variables or methods that are declared in packages  
    imported by the Page Directive, so there is no need to declare them. 
 
In general, a declaration has page scope, so it is valid in scriptlets,  
expressions, and other declarations within the same JSP source file. But  
if a JSP file includes other files, the rules of scope become a bit trickier.  
The rules of scope for declarations are described below: 
(1) If the JSP source file does not include any other files, declarations have 
    page scope. 
(2) If the JSP source file includes a dynamic file with <jsp:include>,  
    declarations have page scope. 
(3) If the JSP source file includes static files with <jsp:include> or  
    the Include Directive, declarations have translation unit scope.  
    A translation unit is the JSP source file plus all of its static  
    include files, but without any dynamic include files. 
 
-- 
 
※ 修改:·agents 於 Jan  2 15:19:33 修改本文·[FROM:   166.111.54.22] 
※ 来源:·BBS 水木清华站 smth.org·[FROM: 166.111.54.22] 

BBS水木清华站∶精华区