有人碰到过自定义jsp标签时,如果属性值一样,只执行一遍了?
如:
            <r:if roleName="1,3">
                if
                <r:else>
                    else
                </r:else>
            </r:if>            <r:if roleName="1,3">
                if 2
                <r:else>
                    else 2
                </r:else>
            </r:if>roleName属性都是1,3时候,就输出if,没有输出if2
如果改成:
            <r:if roleName="1,3">
                if
                <r:else>
                    else
                </r:else>
            </r:if>            <r:if roleName="3,1">
                if 2
                <r:else>
                    else 2
                </r:else>
            </r:if>
roleName更换了顺序,就会输出if和if2具体代码如下:<?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">
    <description>core library</description>
    <display-name>taglib</display-name>
    <tlib-version>1.0</tlib-version>
    <short-name>date</short-name>
    <uri>http://zhaopin.renren.com/jsp/tag/role</uri>
    <tag>
        <description>The Tags used for role control</description>
        <name>role</name>
        <tag-class>com.renren.zhaopin.crm.tag.RoleTag</tag-class>
        <body-content>JSP</body-content>
        <attribute>
            <description>Role Display</description>
            <name>roleName</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>    <tag>
        <description>The Tags used for role control</description>
        <name>if</name>
        <tag-class>com.renren.zhaopin.crm.tag.IfTag</tag-class>
        <body-content>JSP</body-content>
        <attribute>
            <description>Role Display</description>
            <name>roleName</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>    <tag>
        <description>The Tags used for role control</description>
        <name>else</name>
        <tag-class>com.renren.zhaopin.crm.tag.ElseTag</tag-class>
        <body-content>JSP</body-content>
    </tag></taglib>
package com.renren.zhaopin.crm.tag;import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import java.io.IOException;
import java.util.Set;/**
 * User: Administrator
 * Date: 12-10-21
 * Time: 下午2:58
 */
public class IfTag extends BodyTagSupport {
    private boolean flag = false;
    public IfTag() {
        super();
        init();
    }    @Override
    public void release() {
        super.release();
        init();
    }    @Override
    public int doStartTag() throws JspException {
        if(flag){
            this.succeeded();
        }
        return EVAL_BODY_BUFFERED;
    }    @Override
    public int doEndTag() throws JspException {
        try {
            if(subtagSucceeded)
                pageContext.getOut().write(getBody());
        } catch (IOException e) {
            throw new JspException("IOError while writing the body: " + e.getMessage(), e);
        }        init();
        return super.doEndTag();
    }    private String body = null;        //    用于存放成功条件后的内容
    public void setBody(){
        if(body == null){
            body = bodyContent.getString().trim();
        }
    }    private String getBody(){
        if(body == null)
            return bodyContent.getString().trim();
        else
            return body;
    }    /**
     * 判断if 或者 子 else if是否提交成功
     */
    private boolean subtagSucceeded;    /**
     * 子条件判断成功
     */
    public void succeeded(){
        subtagSucceeded = true;
    }
    /**
     * 是否已经执行完毕
     * @return
     */
    public boolean isSucceeded(){
        return subtagSucceeded;
    }    private void init() {
        flag = false;
        subtagSucceeded = false;
        body = null;
    }    private String roleName;    public void setRoleName(String roleName) {
        Set<Integer> setRole = (Set) pageContext.getSession().getAttribute("_my_right");
        if (null != setRole) {
            for(String val : roleName.split(",")){
                if(setRole.contains(Integer.valueOf(val))){
                    this.flag = true;
                    return;
                }
            }
        }
    }
}package com.renren.zhaopin.crm.tag;import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;/**
 * User: Administrator
 * Date: 12-10-21
 * Time: 下午3:02
 */
public class ElseTag extends BodyTagSupport {
    public void release() {
        super.release();
    }    public int doStartTag() throws JspException {
        Tag parent = getParent();        if(parent==null || !(parent instanceof IfTag)){
            throw new JspTagException("else tag must inside if tag");
        }        IfTag ifTag = (IfTag)parent;
        if(ifTag.isSucceeded()){
            // 已经有执行成功的条件,保存之前的html
            ifTag.setBody();
        }else{
            // 之前没有的判断没有成功条件,则清除之前的输出
            ifTag.getBodyContent().clearBody();
            ifTag.succeeded();
        }        return EVAL_BODY_BUFFERED;
    }
}有人碰到过么?是不是jsp有缓存?因为执行第二次该标签的时候,就没有执行属性的set方法即: public void setRoleName(String roleName) {
        Set<Integer> setRole = (Set) pageContext.getSession().getAttribute("_my_right");
        if (null != setRole) {
            for(String val : roleName.split(",")){
                if(setRole.contains(Integer.valueOf(val))){
                    this.flag = true;
                    return;
                }
            }
        }
    }
方法没执行