I have this code
<%!
public String class_name = "";
%>
<c:choose>
<c:when test="${WCParam.categoryId != null}">
<% class_name = "my_account_custom"; %>
</c:when>
<c:otherwise>
<% class_name = "my_account_custom_3"; %>
</c:otherwise>
</c:choose>
<p>Class name = <c:out value='${class_name}' /></p>
WCParam.categoryId is null or not But my class_name variable is always empty. What i am doing wrong Thanks
Scriptlets (<%...%>
) and expression language (${...}
) are completely different things, therefore their variables belong to different scopes (variables used in EL expressions are actually request attributes of different scopes).
If you decalred class_name
as a scriptlet variable, you should access it using scriptlet as well:
<p>Class name = <c:out value='<%=class_name%>' /></p>
However, you can write it without using a variable at all:
<p>Class name = <c:out
value='${WCParam.categoryId != null ? "my_account_custom" : "my_account_custom3"}' /></p>
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