在我的攔截器,如果用戶沒有足夠的權利,將有一個警告消息:Struts 2如何顯示保存在攔截器中的消息,該攔截器會重新導向到另一個動作?
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext actionContext = invocation.getInvocationContext();
Map<String, Object> sessionMap = actionContext.getSession();
User loginUser = (User) sessionMap.get("user");
Object action = invocation.getAction();
if (loginUser != null && loginUser.getRole().getId() != Constant.AUTHORITY_ADMIN) {
((ValidationAware) action).addFieldError("user.authority",
((DefaultAction) action).getText("user.action.authority.not.enough"));
return DefaultAction.HOME_PAGE;
}
return invocation.invoke();
}
然後,它會重定向到「HOME_PAGE」動作,如果成功,顯示在jsp信息。那麼如何顯示警告消息?
我用了兩個攔截器strust.xml的ConfigEd,對於管理權需求量的:
<interceptor-stack name="authorityStack">
<interceptor-ref name="authority" />
<interceptor-ref name="defaultStack" />
<interceptor-ref name="store">
<param name="operationMode">STORE</param>
</interceptor-ref>
</interceptor-stack>
默認爲:
<interceptor-stack name="default">
<interceptor-ref name="login" />
<interceptor-ref name="defaultStack" />
<interceptor-ref name="store">
<param name="operationMode">AUTOMATIC</param>
</interceptor-ref>
</interceptor-stack>
如果用戶試圖調用他們無權訪問的操作,你只是想找一種機制向用戶顯示一條消息? – 2011-01-08 02:53:36