Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jstl - how to ask from jsp if an object does not exist?  RSS feed

 
Marco Vanoli
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my jsp i have to make an if with jstl about an object retrived from session scope. Sometimes that object does not exist at all, and the system give me an error that object is not in the scope.
Can i use some tag for ask if the object exist without displayng errors or i have in all case to send to the page an object ( x example null for make a test as if is not null)? [ i would like to use the first method ]

Also can someone indicate to me a good reference on jstl or some tutorial(not java sun one )?

tnks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should have a copy of the JSTL Specification open on your desk.

To test whethere an object exists you can use the empty operator. But note that this does not distinguish between and object not existing and being empty (such as a zero-length string, or empty array) if that distinction is important to you.
 
chowdary Thammineedi
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<c:if test="${yourObject ne null && whatever}" scope="whatever">
your thing to do
</c:if>

<c:if test="${yourObject eq null && whatever}" scope="whatever">
your thing to do
</c:if>
 
Marco Vanoli
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
You should have a copy of the JSTL Specification open on your desk.

To test whethere an object exists you can use the empty operator. But note that this does not distinguish between and object not existing and being empty (such as a zero-length string, or empty array) if that distinction is important to you.


thnak you, can you gimme the link to specification too?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are better idioms for an if-then-else construct than using two <c:if> tags each of which had converse representations of the same expression.

One doesn't use <c:if> at all:



the other uses three <c:if> tags:



Notice that in both of these idioms the test expression appears only once, eliminating the possibility of the expression and its converse getting out of synch with each other.
[ September 11, 2005: Message edited by: Bear Bibeault ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!