JSP中存在检查属性 [英] Checking attribute exists in JSP
本文介绍了JSP中存在检查属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些扩展了超类的类,在JSP中,我想显示这些类的一些属性.我只想制作一个JSP,但我不事先知道对象是否具有属性.因此,我需要一个JSTL表达式或一个标记来检查我传递的对象是否具有此属性(类似于javascript中的in运算符,但在服务器中).
I have some classes which extends a superclass, and in the JSP I want to show some attributes of these classes. I only want to make one JSP, but I don't know in advance if the object has an attribute or not. So I need a JSTL expression or a tag which checks that the object I pass has this attribute (similar to in operator in javascript, but in the server).
<c:if test="${an expression which checks if myAttribute exists in myObject}">
<!-- Display this only when myObject has the atttribute "myAttribute" -->
<!-- Now I can access safely to "myAttribute" -->
${myObject.myAttribute}
</C:if>
我怎么能得到这个?
谢谢.
推荐答案
Make use of JSTL c:catch
.
<c:catch var="exception">${myObject.myAttribute}</c:catch>
<c:if test="${not empty exception}">Attribute not available.</c:if>
这篇关于JSP中存在检查属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文