一、自定义标签helloworld:

二、自定义有属性的标签:

HelloWorldTag.java:继承TagSupport:

 1 package com.java1234.tag;
 2 
 3 import java.io.IOException;
 4 
 5 import javax.servlet.jsp.JspException;
 6 import javax.servlet.jsp.JspWriter;
 7 import javax.servlet.jsp.tagext.TagSupport;
 8 
 9 public class HelloWorldTag extends TagSupport{
10         
11     private static final long serialVersionUID = 1L;
12     
13     private String name;
14     
15     public String getName() {
16         return name;
17     }
18 
19     public void setName(String name) {
20         this.name = name;
21     }
22 
23     @Override
24     public int doStartTag() throws JspException {
25         JspWriter out=this.pageContext.getOut();
26         try {
27             out.println(name + "自定义标签你好!");
28         } catch (IOException e) {
29             e.printStackTrace();
30         }
31         return TagSupport.SKIP_BODY; // 直接结束标签
32     }
33 }
View Code

相关文章:

猜你喜欢
  • 2022-02-09
  • 2021-08-10
  • 2022-01-04
  • 2021-07-16
  • 2021-06-14
  • 2021-09-18
相关资源
相似解决方案