I am trying string comparison with
<c:if test="${dept eq 'account'}"></c:if>
But this always returns false
. I check the dept variable had the value 'account'
. I also tried like this
<c:if test="${dept == 'account'}"></c:if>
This also returns false
.
But if I use the java code like this then it works fine
<%
if(dept.equals("account")){
blah blah blah
}
%>
Any help would be really appreciated.
Thanks
The symptoms indicate that you've declared it in the scriptlet scope, not in the EL scope. Scriptlets and EL doesn't share the same scope. EL uses under the covers PageContext#findAttribute()
to resolve the variable. Put dept
in one of the page, request, session or application scopes. Which one to choose depends on the sole purpose of dept
itself. I'd start with the request scope. E.g. in a servlet:
request.setAttribute("dept", dept);
This way it'll be available in EL by ${dept}
.
After all, best is to avoid using scriptlets completely. Java code belongs in Java classes, not in JSP files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With