Java中filter內處理重定向遇到的問題


這是在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

 

看來這兩種方式都行不通,之后找其他方法了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM