您现在的位置是:网站首页> 编程资料编程资料
jsp自定义标签之ifelse与遍历自定义标签示例_JSP编程_
                     2023-05-25
                123人已围观
                
                2023-05-25
                123人已围观
            
简介 jsp自定义标签之ifelse与遍历自定义标签示例_JSP编程_
                第一个示例: 
简单的jsp自定标签获取内容:
首先创建一个jsp实例类然后继承SimpleTagSupport类
然后实现父类的doTag()方法
在这个方法里获取标签体里的内容this.getJspBody();
返回的是JspFragment 类,根据这个类对象调用invoke(this.getJspContext().getOut());
这个方法里面也可以写空,所表达的意思也是输出到浏览器;
public class SimpleDmeo1 extends SimpleTagSupport {
@Override
public void doTag() throws JspException, IOException {
JspFragment js =this.getJspBody();
js.invoke(null);
}
}
然后在写tld文件标签库描述文件,和jsp文件,这些都较为简单
如果不想执行某个内容就抛出异常
throw new skipPageException();和面内容就不会显示
接下来是一个带属性的jsp自定义标签文件
public class SimpleDmeo1 extends SimpleTagSupport {
private int counts;
public void setCounts(int counts) {
this.counts = counts;
}
@Override
public void doTag() throws JspException, IOException {
JspFragment js =this.getJspBody();
for(int i=0;ijs.invoke(null); 
}
}
}
A tag library exercising SimpleTag handlers. 
1.0 
c 前缀名 
http://www.csdn.com 
demo 
com.csdn.simple.SimpleDmeo1 
scriptless 
counts 
true 
true 
 
然后再jsp文件 中写出内容;
aaaaaaa
  //输出三编 
JspFragment js = this.getJspBody();
StringWriter jw = new StringWriter();
js.invoke(jw);
String s = jw.toString().toUpperCase();
JspWriter out =this.getJspContext().getOut();
for(int i=0;iout.print(s); 
}
}
 
这是转成大写的代码,其他的都一致;
关于if else的代码,太多,我放到资源里了,有必要的话可以下载下来,仅供参考。
        简单的jsp自定标签获取内容:
首先创建一个jsp实例类然后继承SimpleTagSupport类
然后实现父类的doTag()方法
在这个方法里获取标签体里的内容this.getJspBody();
返回的是JspFragment 类,根据这个类对象调用invoke(this.getJspContext().getOut());
这个方法里面也可以写空,所表达的意思也是输出到浏览器;
复制代码 代码如下:
public class SimpleDmeo1 extends SimpleTagSupport {
@Override
public void doTag() throws JspException, IOException {
JspFragment js =this.getJspBody();
js.invoke(null);
}
}
然后在写tld文件标签库描述文件,和jsp文件,这些都较为简单
如果不想执行某个内容就抛出异常
throw new skipPageException();和面内容就不会显示
接下来是一个带属性的jsp自定义标签文件
复制代码 代码如下:
public class SimpleDmeo1 extends SimpleTagSupport {
private int counts;
public void setCounts(int counts) {
this.counts = counts;
}
@Override
public void doTag() throws JspException, IOException {
JspFragment js =this.getJspBody();
for(int i=0;i
}
}
}
然后再jsp文件 中写出内容;
复制代码 代码如下:
JspFragment js = this.getJspBody();
StringWriter jw = new StringWriter();
js.invoke(jw);
String s = jw.toString().toUpperCase();
JspWriter out =this.getJspContext().getOut();
for(int i=0;i
}
}
这是转成大写的代码,其他的都一致;
关于if else的代码,太多,我放到资源里了,有必要的话可以下载下来,仅供参考。
您可能感兴趣的文章:
                
                
 
                                
                                                         
                                
                                                         
                                
                                                         
 
    