问题
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>
回答1:
<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?
回答2:
Scriptlet variables is not accessible to any scope. You can only use them with scriptlet expressions.
In the Struts is possible to use JSTL along with Struts tags
<c:set var="myValue" value="2"/>
<c:if test="${myValue == 2}">
if test works!
</c:if>
来源:https://stackoverflow.com/questions/19979470/struts-logic-tag-equals-not-working