![](/img/trans.png)
[英]How to set the Struts2 Action defined in struts.xml to PortletURL
[英]Struts2 - How to redirect to an action without using struts.xml?
如果用戶未登錄,我的網絡服務器將阻止對系統的訪問,但是某些用戶可能具有多個配置文件,並且系統僅允許用戶登錄以選擇其中一個配置文件,即某個用戶可能是具有某些權限的普通用戶並且該用戶可以退出並使用管理員權限再次登錄,並可以訪問所有內容。
發生這種情況時,我會將用戶重定向到一個強制用戶選擇其個人資料的操作,但是服務器不再知道該用戶嘗試訪問的操作。 我可以通過ActionInvocation檢索此信息,如下所示:
public String initFeature() {
final ActionInvocation invocation = ServletActionContext.getActionContext(BaseAction.getRequest())
.getActionInvocation();
final Object action = invocation.getAction();
if (!this.isUserFullyLogged() && !(action instanceof ProfileSelectionAction)) {
final Boolean isPendingProfileSelection = (Boolean) this
.retrieveSessionAttribute(Constants.PENDING_PROFILE_SELECTION);
if (isPendingProfileSelection != null && isPendingProfileSelection.booleanValue()) {
this.saveSessionAttribute("action", action);
this.saveSessionAttribute("namespace", invocation.getProxy().getNamespace());
return Constants.PROFILE_SELECTION;
}
return Action.LOGIN;
}
return Action.SUCCESS;
}
當系統執行配置文件選擇操作時,我具有用戶嘗試訪問且被禁止的操作和名稱空間,但是我不知道該將系統重定向到該名稱空間和操作該怎么做,因為我只做了到目前為止,它使用的是struts.xml文件的操作結果。
您可以在struts.xml
文件的result
配置中使用參數。 在操作類內部創建兩個屬性,它們將保存操作的名稱和名稱空間,並在struts.xml
使用它們,如下所示:
<action name="..." class="...">
<result type="redirectAction">
<param name="actionName">${action}</param>
<param name="namespace">${namespace}</param>
</result>
</action>
另外,如果不想創建它們並且您已經將變量存儲在會話中,則也可以使用#session
表達式從會話中檢索它們。
<action name="..." class="...">
<result type="redirectAction">
<param name="actionName">${#session.action}</param>
<param name="namespace">${#session.namespace}</param>
</result>
</action>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.