這是在Java中filter內處理重定向遇到的問題。本意是寫一個做URL rewrite 的filter,來重寫URL,同時在處理登陸過程中要殺掉當前session,創建新session來代替。
1. 如果在filter中,先call了response.sendRedirect(),然后執行chain.doFilter(),然后在后續處理中把當前session invalidate,再create new session,遇到了錯誤:
java.lang.IllegalStateException: Cannot create a session after the response has been committed
2. 如果在filter中,先執行chain.doFilter(),再做session invalidate,create new session,然后在返回到filter中執行doFilter的后續部分,在這時候sendRedirect,就出現了下面的錯誤:
java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
看來這兩種方式都行不通,之后找其他方法了。