我正在尝试访问JSP中struts2 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
。有什么问题?
答案 0 :(得分:1)
问题是动作上下文中没有名为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()">
答案 1 :(得分:0)
这终于工作了
<%
Website website = (Website)request.getAttribute(Website.NAME);
out.println(website.isUkSite()); // prints true
%>
<s:if test="website.ukSite">
// this is executed finally !!
</s:if>