[英]JSF: How to redirect a user to a another page according to the value of a specific FacesContext session attribute
[英]How to redirect to error page in JSF when FacesContext session attribute is not found
我正在使用JSF和Apache myFaces 1.2.9開發移動Web應用程序。
在身份驗證期間,我正在調用一個servlet,它將進行身份驗證,然后在會話中設置一些屬性。
並且在每個托管bean構造函數中,我都在檢查此session屬性,並因此設置了一個布爾值。我將該布爾值設置為tr:document的呈現屬性的值。
<tr:document title="someid" rendered="#{controller.render}">
//SOME PAGE CONTENTS
</tr:document>
根據會話屬性,頁面是否可以呈現。我想更優雅地處理此問題。
我來過這個問題,在SO告訴filters.I的用途使用的過濾器如圖所示這里 。
我將webFilter urlPattern更改為/faces/jsp/*
因為我想檢查每個jsp的會話屬性。
在doFilter()方法中,我正在像這樣檢查會話屬性,如果它為null
我將重定向到無效的用戶頁面。
System.out.println("In doFilter");
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession(false);
if (session.getAttribute("myattribute") == null) {
response.sendRedirect(properties.getProperty(INVALID_USER_REDIRECTURL, true)); // No attribute found, so redirect to Invalid user page.
} else {
chain.doFilter(req, res); // attribute found, so just continue request.
}
但是我看不到我的過濾器被解雇,因為我看不到我的過濾器init(),doFilter()
方法中保留的任何調試語句。
有什么幫助嗎?
編輯:我只是通過了我的web.xml中的此過濾器映射
<filter>
<filter-name>trinidad</filter-name>
<filter-class>org.apache.myfaces.trinidad.webapp.TrinidadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>trinidad</filter-name>
<servlet-name>faces</servlet-name>
</filter-mapping>
我想我的臉有過濾器,我可以再換一個嗎?
將過濾器映射到將FacesServlet映射到的URL模式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.