zoukankan      html  css  js  c++  java
  • JSP三种页面跳转方式的比较

    使用JSP大约有下列三种跳转方式:

    1 response.sendRedirect();
    2 response.setHeader("Location","");
    3 <jsp:forward page="" />

    经过试验得到下面的一些规则:

      一. response.sendRedirect()

      此语句前不允许有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的操作已经无意义了;
      如果较嗤骰拢擞锞浜竺娴挠锞渲葱型瓿珊蟛呕崽?BR>

      二. response.setHeader("Location","")

      此语句前不允许有out.flush(),如果有,页面不会跳转。
      跳转后浏览器地址栏变化
      此语句后面的语句执行完成后才会跳转
      三. <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)
      ...

      跳转后浏览器地址栏不变,但是只能跳到当前主机下
      此语句后面的语句执行完成后才会跳转



  • 相关阅读:
    20191028 Codeforces Round #534 (Div. 1)
    20191028 牛客网CSP-S Round2019-1
    UVA11464 Even Parity 搜索+递推
    CSP2019-S1 游记
    LG2921 [USACO2008DEC]Trick or Treat on the Farm 内向基环树
    bzoj 2002 Bounce 弹飞绵羊
    快速乘,快速幂,十进制快速幂,矩阵快速幂
    2019牛客暑期多校训练营(第五场) generator 1
    2019牛客暑期多校训练营(第五场) digits 2
    hdu 4714 Tree2cycle
  • 原文地址:https://www.cnblogs.com/javadu/p/2282774.html
Copyright © 2011-2022 走看看