JSP中的Simple自定义标签使用
2011-11-10 08:12
381 查看
Simple自定义标签使用
今天我们主要讲一下我们的simple这个自定义标签的使用!首先我们看一下simple这个是怎么使用的。
我们先看一下java类,首先java类要继承SimpleTagSupport类。
第一个实例:我们是输出那个自定义标签的内容。
我们重写doTag方法 这样写JspFragment jf=this.getJspBody();我们就获取到了jf这个被容的对象,然后我们用jf.invoke(null);就能输出了,这里的null不是输出是空的。
第二个实例:获取属性
在对应的类中写到的属性名称要和你在自定义方法中定义的一样。而且我们还得写一个setter方法。一定要按正确的格式。下面给一个例子 是一个count的例子 <tag>
<description>display user ip</description>
<name>Demo8</name>
<tag-class>com.web.tag.Demo8</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>count</name>
<required>yes</required>
<rtexprvalue>yes</rtexprvalue>
</attribute>
</tag>
public class Demo8 extends SimpleTagSupport{
privateint count;
publicvoid setCount(int count) {
this.count= count;
}
@Override
publicvoid doTag() throws JspException, IOException {
JspFragmentjf=this.getJspBody();
for(int i = 0; i < count; i++) {
jf.invoke(null);
}
}
<hbsi:Demo8count="5" >
This is my JSP page. <br>
</hbsi:Demo8>
这就是重复5次 如果在多name我们更改就行了
实例三:大小写转换
<hbsi:Demo9>
This is my JSP page. <br>
</hbsi:Demo9>
publicvoid doTag() throws JspException, IOException {
JspFragmentjf=this.getJspBody();
StringWritersw=new StringWriter();
jf.invoke(sw);
Stringcontent=sw.toString().toUpperCase();
JspWriterjw=this.getJspContext().getOut();
jw.write(content);
}
这就变成了大写的了
今天我们主要讲一下我们的simple这个自定义标签的使用!首先我们看一下simple这个是怎么使用的。
我们先看一下java类,首先java类要继承SimpleTagSupport类。
第一个实例:我们是输出那个自定义标签的内容。
我们重写doTag方法 这样写JspFragment jf=this.getJspBody();我们就获取到了jf这个被容的对象,然后我们用jf.invoke(null);就能输出了,这里的null不是输出是空的。
第二个实例:获取属性
在对应的类中写到的属性名称要和你在自定义方法中定义的一样。而且我们还得写一个setter方法。一定要按正确的格式。下面给一个例子 是一个count的例子 <tag>
<description>display user ip</description>
<name>Demo8</name>
<tag-class>com.web.tag.Demo8</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>count</name>
<required>yes</required>
<rtexprvalue>yes</rtexprvalue>
</attribute>
</tag>
public class Demo8 extends SimpleTagSupport{
privateint count;
publicvoid setCount(int count) {
this.count= count;
}
@Override
publicvoid doTag() throws JspException, IOException {
JspFragmentjf=this.getJspBody();
for(int i = 0; i < count; i++) {
jf.invoke(null);
}
}
<hbsi:Demo8count="5" >
This is my JSP page. <br>
</hbsi:Demo8>
这就是重复5次 如果在多name我们更改就行了
实例三:大小写转换
<hbsi:Demo9>
This is my JSP page. <br>
</hbsi:Demo9>
publicvoid doTag() throws JspException, IOException {
JspFragmentjf=this.getJspBody();
StringWritersw=new StringWriter();
jf.invoke(sw);
Stringcontent=sw.toString().toUpperCase();
JspWriterjw=this.getJspContext().getOut();
jw.write(content);
}
这就变成了大写的了
相关文章推荐
- 自定义JSP中的Taglib标签之五自定义标签之SimpleTagSupport使用
- 自定义JSP中的Taglib标签之五自定义标签之SimpleTagSupport使用
- jsp 自定义标签-SimpleTagSupport 使用笔记
- [教程]自定义JSP中的Taglib标签之五自定义标签之SimpleTagSupport使用
- 自定义JSP标签库及Properties使用
- JSP自定义标签使用
- 使用BodyTagSupport类实现Jsp自定义标签
- 基于JSP 自定义标签使用实例介绍
- 使用JSP自定义标签做页面片段的缓存
- 使用JSTL开发jsp自定义标签开发
- JSP中如何使用自定义的标签库
- 将自定义标签打包为jar包并提供给JSP使用
- JSP 2.x用SimpleTag开发自定义标签的方法
- 使用JSTL开发jsp自定义标签开发---迭代标签
- Java创建自定义标签SimpleTagSupport并在页面中使用
- 学会怎样使用Jsp 内置标签、jstl标签库及自定义标签
- Jsp自定义标签使用笔记
- 使用SimpleTag支持自定义JSP标签
- Java - 使用标签库有什么好处?如何自定义JSP标签?
- 关于打包自定义标签,并导入项目使用时,出现java.lang.NoClassDefFoundError: JspException异常,解决方法和注意事项!