2012-10-17 42 views
0

我不知道我的許可檢查是否正確,但我是這樣做的。struts2,使用靜態參數調用會話變量方法

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 
    } 
} 

在我的JSP,我想隱藏一個按鈕,如果它被保存在session中「當前用戶」的用戶不具有「save.settings的許可。

組織我的代碼,我宣佈一個接口:

public interface Permission { 
    public static final String SAVE_SETTINGS = "save.settings"; 
} 

使權限檢查時,我只是訪問我的JSP中的靜態變量。

現在我該如何在JSP中執行此操作?我試過...

<s:if test="{#session.currentUser.hasPermission(@[email protected]_SETTINGS)}"> 
    <div> 
     <input id="iSave" type="button" value="Save" /> 
    </div> 
</s:if> 

但它沒有工作。

<constant name="struts.ognl.allowStaticMethodAccess" value="true"/> 

也在我的struts.xml

任何想法傢伙設定?

+0

作爲一個全面的檢查,如果你使用''查看靜態無功,它的工作原理? –

回答