当前位置:编程学习 > JAVA >>

关于jsp有体标签问题

为什么bodyContent的值是null 为什么没有获得值 是要初始化一下吗? --------------------编程问答-------------------- Select all valid values for the <body-content> attribute in a TLD? [Check all correct answers] 
1. empty 2. JSP 3. dependent 4. HTML 5. code 
Answers given by j2eecertificate.com is : 1 & 2. 
According to me "JSP" is invalid. I checked the spec, it gave the following examplination 
<Spec> 
A TLD is invalid if it specifies JSP as the value for 
<body-content> for a tag whose handler implements the SimpleTag inte易做图ce. JSP containers are recommended to but not required to produce an error if JSP is specified in this case. 
</spec> 
So does this mean the JSP can be one of the values in the <Body-content> attribute. 
shashank 

http://java.itags.org/java-certification/9145/ 
--------------------编程问答--------------------

package zl.framework.tag;

import javax.servlet.jsp.JspException;

/**
 * 逻辑控制的相等判断
 * @author xjl
 * @version 2.0
 */
public class EqualTag extends BaseTag {

private static final long serialVersionUID = 1L;
private String name;
private String scope;
private String value;
private String compare;

public int doStartTag() throws JspException {
return super.doStartTag();
}

public void doInitBody() throws JspException {   
        super.doInitBody();   
    }   

public int doAfterBody() throws JspException {
return EVAL_PAGE;
}

public int doEndTag() throws JspException {
write(getBody(name, scope, value, compare, 4));
return super.doEndTag();
}

/**
 * 取值的依据
 * @param name 
 */
public void setName(String name) {
this.name = name;
}

/**
 * 取值作用域
 * @param scope 默认优先级为page--request--session--application
 */
public void setScope(String scope) {
this.scope = scope;
}

/**
 * 要比较的值
 * @param value
 */
public void setValue(String value) {
this.value = value;
}

/**
 * 要比较的值存放的依据(优先级比value高)
 * @param compare
 */
public void setCompare(String compare) {
this.compare = compare;
}

}




/**
 * 逻辑控制时获得页面输出内容
 * @param name 取值的依据
 * @param scope 取值作用域
 * @param value 要比较的值
 * @param compare 要比较的值存放的依据
 * @param logicIndex 逻辑运算符的索引
 * @return String
 */
public String getBody(String name, String scope, String value, String compare, int logicIndex) {
Object compareObject = getCompareObject(compare, value, scope);
int index = getNumberSign(name);
Object object = getObject(index, name, scope);
if (null != object && null != compareObject) {
if (index >= 0) {
if (compare(StringToMath(getOperatValue(name, object, index), object.getClass()), compareObject, logicIndex)) {
return (null != getBodyContent()) ? getBodyContent().getString() : "";
}
} else {
if (compare(object, compareObject, logicIndex)) {
return (null != getBodyContent()) ? getBodyContent().getString() : "";
}
}
}
if (null == object && null != compareObject && logicIndex == 5) {
return (null != getBodyContent()) ? getBodyContent().getString() : "";
}
if (null != object && null == compareObject && logicIndex == 5) {
return (null != getBodyContent()) ? getBodyContent().getString() : "";
}
return "";
}


<tag>
<description>逻辑控制的相等判断</description>
   <name>equal</name>
   <tag-class>zl.framework.tag.EqualTag</tag-class>
   <body-content>JSP</body-content>
   <attribute>
   <description>取值的依据</description>
       <name>name</name>
       <required>true</required>
       <rtexprvalue>false</rtexprvalue>
     </attribute>
     <attribute>
   <description>取值的作用域,默认优先级为page--request--session--application</description>
       <name>scope</name>
       <required>false</required>
       <rtexprvalue>false</rtexprvalue>
     </attribute>
     <attribute>
   <description>要比较的值</description>
       <name>value</name>
       <required>false</required>
       <rtexprvalue>false</rtexprvalue>
     </attribute>
     <attribute>
   <description>要比较的值存放的依据(优先级比value高)</description>
       <name>compare</name>
       <required>false</required>
       <rtexprvalue>false</rtexprvalue>
     </attribute>
</tag>
补充:Java ,  Web 开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,