我正在尝试访问 JSP 中 Struts 2
<s:if>
标记内的 scriptlet 变量:
<%
Website website = (Website)request.getAttribute(Website.NAME);
out.println(website.isUkSite()); // prints true
%>
<s:if test="#website.isIrishSite()"> // this is returning false
....
实际上这个
<s:if>
标签应该评估为 true
。
问题是什么?
问题是操作上下文中没有名为
website
的变量。为了使其正常工作,您可以使用
<%
Website website = (Website)request.getAttribute(Website.NAME);
out.println(website.isUkSite()); // prints true
ActionContext.getContext().put("website", website);
%>
但是 scriplets 是一个糟糕的选择,你可以删除此代码并使用
<s:if test="#request.website.isIrishSite()">
终于成功了
<%
Website website = (Website)request.getAttribute(Website.NAME);
out.println(website.isUkSite()); // prints true
%>
<s:if test="website.ukSite">
// this is executed finally !!
</s:if>