JSP轉向另一地址

JSP轉向另一地址,
1. response.sendRedirect(); 2 <jsp:forward page="" />
兩區別:1.此語句前不允許有out.flush(),如果有,會有異常: java.lang.IllegalStateException: Can't sendRedirect() after data has committed to the client.  at com.caucho.server.connection.AbstractHttpResponse.sendRedirect(AbstractHttpResponse.java:558) ... 跳轉後瀏覽器地址欄變化如果要跳到不同主機下,跳轉後,此語句後面的語句會繼續執行,如同新開了線程,但是對response的操作已經無意義了;如果要跳到相同主機下,此語句後面的語句執行完成後纔會跳轉; 2.<jsp:forward page="" />

此語句前不允許有out.flush(),如果有,會有異常: java.lang.IllegalStateException: forward() not allowed after buffer has committed.  at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:134)  at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:101)  at com.caucho.jsp.PageContextImpl.forward(PageContextImpl.java:836)  ... 跳轉後瀏覽器地址欄不變,但是隻能跳到當前主機下此語句後面的語句執行完成後纔會跳轉不過這方法可以隱藏地址欄不變.在有些情況下可能要用到...

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章