开发自定义标签的步骤:
1.开发一个顶顶与标签处理类
2.建立一个*.tld的文件 一个*.tld对应一个标签库,每个标签库可以有多个标签
3.在jsp中使用
1.1.开发一个顶顶与标签处理类
public class HelloWorldTag extends SimpleTagSupport{
private String yourname; //这些有getter setter的参数是使用标签时用的参数
private String youraddress;
@Override
//doTag标签式处理标签的最重要的方法
public void doTag() throws JspException, IOException {
getJspContext().getOut().write("Hello World!"+yourname+youraddress);
}
public String getYourname() {
return yourname;
}
public void setYourname(String yourname) {
this.yourname = yourname;
}
public String getYouraddress() {
return youraddress;
}
public void setYouraddress(String youraddress) {
this.youraddress = youraddress;
}
}
2.建立一个*.tld的文件 一个*.tld对应一个标签库,每个标签库可以有多个标签
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<tlib-version>1.0</tlib-version>
<short-name>SimpleTagLibrary</short-name>
<uri>http://www.lubby.com</uri> //这个是标签库的 URI
<tag>
<name>helloworld</name> //标签名
<tag-class>com.lubby.tag.HelloWorldTag</tag-class> //该标签的处理类
<body-content>empty</body-content>
<attribute>//标签参数
<name>yourname</name>
<required>true</required>
<fragment>true</fragment>
</attribute>
<attribute>
<name>youraddress</name>
<required>true</required>
<fragment>true</fragment>
</attribute>
</tag>
3.在jsp中使用
<%@ taglib prefix="my" uri="http://www.lubby.com" %>
<my:helloworld yourname="Tom" youraddress="SuZhouSchool"/>
1.开发一个顶顶与标签处理类
2.建立一个*.tld的文件 一个*.tld对应一个标签库,每个标签库可以有多个标签
3.在jsp中使用
1.1.开发一个顶顶与标签处理类
public class HelloWorldTag extends SimpleTagSupport{
private String yourname; //这些有getter setter的参数是使用标签时用的参数
private String youraddress;
@Override
//doTag标签式处理标签的最重要的方法
public void doTag() throws JspException, IOException {
getJspContext().getOut().write("Hello World!"+yourname+youraddress);
}
public String getYourname() {
return yourname;
}
public void setYourname(String yourname) {
this.yourname = yourname;
}
public String getYouraddress() {
return youraddress;
}
public void setYouraddress(String youraddress) {
this.youraddress = youraddress;
}
}
2.建立一个*.tld的文件 一个*.tld对应一个标签库,每个标签库可以有多个标签
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<tlib-version>1.0</tlib-version>
<short-name>SimpleTagLibrary</short-name>
<uri>http://www.lubby.com</uri> //这个是标签库的 URI
<tag>
<name>helloworld</name> //标签名
<tag-class>com.lubby.tag.HelloWorldTag</tag-class> //该标签的处理类
<body-content>empty</body-content>
<attribute>//标签参数
<name>yourname</name>
<required>true</required>
<fragment>true</fragment>
</attribute>
<attribute>
<name>youraddress</name>
<required>true</required>
<fragment>true</fragment>
</attribute>
</tag>
3.在jsp中使用
<%@ taglib prefix="my" uri="http://www.lubby.com" %>
<my:helloworld yourname="Tom" youraddress="SuZhouSchool"/>
2147

被折叠的 条评论
为什么被折叠?



