Jsp 当属性名本身是一个动态变量时,如何获取bean属性的值
我正在尝试编写一个自定义JSPX标记,该标记从给定列表中的每个对象读取给定bean属性的值,并将该属性的名称作为JSP属性传递给标记。标签的外观如下所示:Jsp 当属性名本身是一个动态变量时,如何获取bean属性的值,jsp,properties,javabeans,el,jspx,Jsp,Properties,Javabeans,El,Jspx,我正在尝试编写一个自定义JSPX标记,该标记从给定列表中的每个对象读取给定bean属性的值,并将该属性的名称作为JSP属性传递给标记。标签的外观如下所示: <jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"> <jsp:output omit-xml-declaration=
<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:jsp="http://java.sun.com/JSP/Page"
version="2.0">
<jsp:output omit-xml-declaration="yes"/>
<jsp:directive.attribute name="items" type="java.lang.Iterable"
required="true" description="The items whose properties are to be read"
rtexprvalue="true"/>
<jsp:directive.attribute name="propertyName" type="java.lang.String"
required="true" description="The name of the bean property to read"
rtexprvalue="true"/>
<c:forEach items="${items}" var="item">
<!-- This is the bit that doesn't work -->
<jsp:getProperty name="item" property="${propertyName}" />
</c:forEach>
</jsp:root>
我得到的错误是:
org.apache.jasper.JasperException: org.apache.jasper.JasperException:
PWC6054: Cannot find any information on property '${propertyName}' in
a bean of type 'com.example.FooBar'
感谢您的帮助。如果要使用动态属性名称,请使用大括号表示法
<c:forEach items="${items}" var="item">
${item[propertyName]}
</c:forEach>
${item[propertyName]}
是否有所有此类符号的参考指南?不客气。是的,请查看JavaEE教程中的统一EL章节。具体而言,本部分将在第章中介绍。作为概述可能更方便。@BalusC非常感谢您。。。我在使用jsp:getProperty访问属性时遇到了困难,但工作不正常…:-)
<c:forEach items="${items}" var="item">
${item[propertyName]}
</c:forEach>