---
title: "关于jsptag中teiclass的使用"
author: "pwosboy"
date: "2007-08-22T06:50:31Z"
tags: ["JSP", "Java"]
slug: "jsptag-teiclass"
draft: false
lastmod: "2007-08-22T06:50:31Z"
id: 118754
url: "https://pwosboy.iteye.com/blog/118754"
---

//ListAllBodyTagExtraInfo.java  
public class ListAllBodyTagExtraInfo extends TagExtraInfo {  
public ListAllBodyTagExtraInfo() { }  
/\**  
\* 让JSP引擎确定参数类型  
\*/  
public VariableInfo\[] getVariableInfo(TagData data) {  
　return new VariableInfo\[] {  
　/\**  
　* 参数名，类型，是否声明新变量，范围  
　* 范围取值：AT\_BEGIN,AT\_END,NESTED(标记有效范围内)  
　\*/  
　　new VariableInfo("name", "java.lang.String", true, VariableInfo.NESTED) ,  
　　new VariableInfo("value", "java.lang.Integer", true, VariableInfo.NESTED),  
　};  
}  
}  
定义该函数后，声明正确的tld，可以这么使用

&lt;definetag attr1="value"&gt;  
&lt;%=name%&gt;is &lt;%=value%&gt;  
&lt;/definetag&gt;

##### VariableInfo

```
public VariableInfo(java.lang.String varName,
                    java.lang.String className,
                    boolean declare,
                    int scope)
```

Constructor These objects can be created (at translation time) by the TagExtraInfo instances.

**参数：**

`varName` - The name of the scripting variable

`className` - The type of this variable

`declare` - If true, it is a new variable (in some languages this will require a declaration)

`scope` - Indication on the lexical scope of the variable

**字段摘要**

`static int`  
`AT_BEGIN`  
          Scope information that scripting variable is visible after start tag.

`static int`  
`AT_END`  
          Scope information that scripting variable is visible after end tag.

`static int`  
`NESTED`  
          Scope information that scripting variable is visible only within the start/end tags.![](http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=9060666507596352121&page=RSS%3A%20%E5%85%B3%E4%BA%8Ejsptag%E4%B8%ADteiclass%E7%9A%84%E4%BD%BF%E7%94%A8&referrer=)![](http://c.live.com/c.gif?NC=31263&amp%3BNA=1149&amp%3BPI=88469&amp%3BRF=&amp%3BDI=3919&amp%3BPS=85545&amp%3BTP=pwosboy.spaces.live.com&amp%3BGT1=pwosboy)