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_nameas a scriptlet variable, you should access it using scriptlet as well:However, you can write it without using a variable at all: