jsp自定义c:if标签

jsp自定义c:if标签,第1张

jsp自定义c:if标签

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");
	%>
	
	
	
	
	性别:
	


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5670934.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-17

发表评论

登录后才能评论

评论列表(0条)

    保存