當我的用戶嘗試做一個動作我們的網站後,他們的會話已過期(例如,如果他們離開自己的瀏覽器中打開),服務器與HTTP狀態405響應,因爲用戶不再登錄。如何識別GWT內的http錯誤代碼?
發生這種情況時,我想將用戶重定向到登錄屏幕。
我怎麼能認識時405錯誤代碼中的GWT返回,所以我可以然後重定向用戶?
感謝
編輯: 下面是我使用的過濾器:
public class AuthenticationFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
if (req instanceof HttpServletRequest) {
boolean isLoggedIn = CustomSecurity.login((HttpServletRequest)req);
if (isLoggedIn) {
// TODO: How to redirect the user here???
}
}
chain.doFilter(req, res);
}
public void init(FilterConfig arg0) throws ServletException {
}
}
web.xml中內容:
<filter>
<filter-name>Authentication Filter</filter-name>
<filter-class>com.company.AuthenticationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Authentication Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
我怎樣才能讓中的重定向用戶?另外,有沒有辦法強制整個瀏覽器重定向?由於這進入了一個小部件,我認爲Window.Location.assign('url')只會重定向小部件的HTML內容。
? – LINEMAN78 2011-02-10 21:27:37
我們正在使用GWT-RPC – Cuga 2011-02-10 21:32:39
這種過濾方法只會在會話過期時重定向您的rpc呼叫,您需要將405返回給客戶端。如果你在過濾器中重定向,它會得到一個200,但端點將會改變,gwt不會能夠解析數據。 – LINEMAN78 2011-02-12 22:20:25