所以我有一個我正在開發的Struts2應用程序。在我的首頁上,我有一個部分將顯示我的應用程序拋出的任何異常。這工作得很好,直到我添加了一個自定義攔截器。Struts2應用程序添加攔截器後隱藏我的例外
這裏是我的代碼攔截器:
public String intercept(ActionInvocation actionInvocation) throws Exception {
String result = actionInvocation.invoke();
return result;
}
這是被生成的異常在我的Action類的代碼,它發生在那裏AuthService.Authorize()被調用:
if(AuthService.Authorize(username, password)) {
if(AuthService.AdminAuthorized()) {
return "admin";
}
return SUCCESS;
}
這在AuthService.Authorize()中時,它在訪問acc時拋出空點異常:
try {
acc = profileRepository.WhereSingle("Username", "=", username);
} catch (Exception e) {
return false;
}
if (acc.Password.equals(password)) {
但是,頁面加載時。這不是人口:
<s:property value="%{exception.message}"/>
我測試了它,它會工作,如果我只是從Action類拋出一個異常。我不是調用redirectAction或任何
這裏是我的所有其他包可擴展
<package name="default" namespace="/" extends="struts-default">
<!-- Interceptors -->
<interceptors>
<interceptor name="conversation" class="global.ConversationInterceptor"/>
<interceptor-stack name="dils-stack">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="conversation"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="dils-stack"/>
<global-results>
<result name="Exception" >/index.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="Exception"/>
<exception-mapping exception="java.lang.NullPointerException" result="Exception"/>
</global-exception-mappings>
看到上面,謝謝。 – WSkinner 2010-11-16 15:41:04
在Tomcat 6.x上使用Struts 2.2.1進行了確認。 – 2010-11-16 23:44:31