[英]struts2, Invoke session variable method with static parameter
I don't know if my Permission Checking is right but I'm doing it this way. 我不知道我的权限检查是否正确,但是我是用这种方式做的。
public class User {
public boolean hasPermission (String permission){
// codes here to check from Roles.permissions if permission parameter exists
// return true if exists, otherwise return false
}
}
In my JSP, I want to hide a button if the User which is saved in the session as "currentUser" doesn't have 'save.settings' permission. 在我的JSP中,如果在会话中另存为“ currentUser”的User没有'save.settings'权限,我想隐藏一个按钮。
to organize my codes, I declared an interface: 为了组织代码,我声明了一个接口:
public interface Permission {
public static final String SAVE_SETTINGS = "save.settings";
}
so that I will just access the static variable in my JSP when checking for permission. 这样我就可以在检查权限时访问JSP中的静态变量。
now how do i do this in my JSP? 现在如何在JSP中执行此操作? I tried...
我试过了...
<s:if test="{#session.currentUser.hasPermission(@my.pkg.Permission@SAVE_SETTINGS)}">
<div>
<input id="iSave" type="button" value="Save" />
</div>
</s:if>
but it doesn work. 但这行不通。
<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
is also set in my struts.xml 也在我的struts.xml中设置
Any idea guys? 有想法吗?
Use 采用
<s:if test="#session['currentUser'].hasPermission(@my.pkg.Permission@SAVE_SETTINGS)">
or 要么
<s:if test="#session.currentUser.hasPermission(@my.pkg.Permission@SAVE_SETTINGS)">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.