看项目中的源代码才发现自定义标签中<rtexprvalue>也是个小知识点。
有些小激动的查了下,以下就是查阅别人的博客后的观后感。
rtexprvalue 全称Run - time Expression Value,表示是否可以使用jsp表达式。
rtexprvalue标签在<attribute>标签下面,其中有true,false。
当<rtexprvalue>true</rtexprvalue>时,表示该自定义标签的某个属性的值可以直接指定也可以通过动态计算指定。
<rtexprvalue>false</rtexprvalue>时,表示该自定义标签的某个属性的值只能直接指定。
此处可以看下rtexprvalue标签在attribute标签中的位置:
<tag>
<name>selectDetail</name>
<tag-class>com.nms.taglib.SelectDetail_Tag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>id</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>selectVal</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>collection</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag> 此处给出rtexprvalue标签为true时的例子:
<%
User user = new User();
user.setId(1);
request.setAttribute("user",user);
%>
<html:selectDetail id="" collection="<%="SEX" %>" selectVal="${user.id}"></html:selectDetail>
此处给出rtexprvalue标签为false时的例子:
<html:selectDetail id="" collection="SEX" selectVal="男"></html:selectDetail> 如果还是使用上面为true时的样式,就会报错啦!!
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
此处再说下<body-context>这个标签,有三个值可选:jsp, empty, tagdependent,scriptless
jsp 表示标签体由其他jsp元素组成,比如EL表达式,标准或定制动作以及脚本元素(常用)
如果有jsp元素,那么标签会先解释这些元素,然后再将实际值传入。比如标签体里含有<%= attributeName %>这样的jsp元素,此时标签就会把attributeName的实际值传入进来。
empty 表示标签体必须为空
在引用这个Tag的时候,可以<bean:write bundle="attributeName" />,而不用<bean:write bundle="attributeName"></bean:write>
<span style="font-size:12px;"><body>
<jsp:useBean id="catalog" class="liangchao.bean.chap10.CatalogBean"></jsp:useBean>
<my:forEachOption items="${catalog.productList}" var="product">
${product.name }:${product.price }<br/>
</my:forEachOption>
</body> </span>结果:${product.name
}:${product.price }${product.name }:${product.price }
${product.name }:${product.price }
<body>
<jsp:useBean id="catalog" class="liangchao.bean.chap10.CatalogBean"></jsp:useBean>
<my:forEachOption items="${catalog.productList}" var="product">
${product.name }:${product.price }<br/>
</my:forEachOption>
</body> 结果:
JSP Programming:58.5
Core Java:99.5
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
本文详细介绍了JSP自定义标签中的rtexprvalue和body-content属性的作用及用法。rtexprvalue属性决定了标签属性值是否可以通过表达式动态计算;body-content属性则定义了标签体的内容类型,包括对JSP元素的支持情况。
812

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



