JSTL if tag for equal strings

Niklas R. picture Niklas R. · Apr 17, 2012 · Viewed 317.6k times · Source

I've got a variable from an object on my JSP page:

<%= ansokanInfo.getPSystem() %>

The value of the variable is NAT which is correct and I want to apply certain page elements for this value. How do I use a tag to know the case? I tried something like

<c:if test = "${ansokanInfo.getPSystem() == 'NAT'}">      
   process  
</c:if> 

But the above doesn't display anything. How should I do it? Or can I just as well use scriptlets i.e.

<% if (ansokanInfo.getPSystem().equals("NAT"){ %>
process
<% } %>

Thanks for any answer or comment.

Answer

Adam Gent picture Adam Gent · Apr 17, 2012

Try:

<c:if test = "${ansokanInfo.PSystem == 'NAT'}">

JSP/Servlet 2.4 (I think that's the version number) doesn't support method calls in EL and only support properties. The latest servlet containers do support method calls (ie Tomcat 7).