java代码:
package com.zx.tag;
import java.io.IOException;
import java.io.StringWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
public class IfTag extends SimpleTagSupport {
//1.获取属性名为test的属性值
private boolean test;
public void setAbc(boolean test) {
this.test = test;
}
@Override
public void doTag() throws JspException, IOException {
//2.判断属性值是否为true
if(test) {
//3.根据判断结果决定是否显示标签体的内容
StringWriter sw = new StringWriter();
this.getJspBody().invoke(sw);
this.getJspContext().getOut().write(sw.toString());
}
}
}
tld代码:
自定义标签 zdytag 1.0 zy http://www.zhuoxun/jxb 这个标签用来将标签体的内容小写改大写 if com.zx.tag.IfTag scriptless 条件判断 abc true true
html代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.zhuoxun/jxb" prefix="zy"%>
main
<%
request.setAttribute("address", "TianJin");
String address = "TianJin";
request.setAttribute("sex", "man");
%>
性别:
男



