Preface

Comment

Declaration

Expression

Scriptlet

EL Expression

Directives

Attribute Directive

Include Directive

Page Directive

Tag Directive

Taglib Directive

Variable Directive

Standard Actions

<jsp:attribute>

<jsp:body>

<jsp:element>

<jsp:doBody>

<jsp:forward>

<jsp:getProperty>

<jsp:include>

<jsp:invoke>

<jsp:output>

<jsp:plugin>

<jsp:root>

<jsp:setProperty>

<jsp:text>

<jsp:useBean>

Declaration

Declares a variable or method valid in the scripting language used in the JSP page.

JSP Syntax

<%! declaration; [ declaration; ]+ ... %>  

OR

<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:

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>.

See Also

 



宏飞网络是你学习web开发、测试web程序实例、和培养职业技能的首选网站。我们提供例子也许有些简单,但对理解基本概念有帮助。

我们尽量避免在教程、参考及例子中出现错误,但不能保证所有的内容都是正确的。

你使用本网站时,我们默认你已经阅读并接受了我们的隐私政策。

Copyright 2003-2011宏飞网络 版权所有