Struts logic tag equals not working
13,369
<logic:equal name="myValue" value="2" scope="session">
This tag looks for a session attribute named "myValue". Not for a local variable named "myValue".
The real question is: why are you using a tag library which is marked as deprecated in favor of the JSTL, this library being part of a framework which is officially abandoned?
Author by
KS1
Updated on June 04, 2022Comments
-
KS1 almost 2 years
Very quick questions. Could someone explain to me why this code does not work?
<%@ taglib prefix="logic" uri="/WEB-INF/struts-logic.tld" %> <% int myValue= 2; %> myValue: <%=myValue%> <br/> <logic:equal name="myValue" value="2" scope="session"> logic:equal works! </logic:equal>
Even if I change myValue to a String is still doesn't work
Quite frustrating, cause I know it's going to be something obvious.
Thanks in advance
KS
Working example!
<%@ taglib prefix="logic" uri="/WEB-INF/struts-logic.tld" %> <% request.setAttribute("myValue", 2); %> myValue - <%=request.getAttribute("myValue")%>]] <br/> <logic:equal name="myValue" value="2" scope="request"> logic:equal works! </logic:equal>
-
KS1 over 10 yearsChanged the scope to 'request' but still doesn't work for me.
-
KS1 over 10 yearsI specifically am not using a deprecated library in favor of the JSTL, but the company I work for, is. So I go with the tools handed to me.
-
JB Nizet over 10 yearsChanging the scope to request will make it look for a request attribute named "myValue", not for a local variable named "myValue". Your scriptlet code should do:
request.setAttribute("myValue", 2)
. That will create a request attribute named "myValue". -
KS1 over 10 yearsFantastic, cheers! Edited my original question with the working version.