JSP三种页面跳转方式的比较
来源:互联网 发布:直线插补算法 编辑:程序博客网 时间:2024/06/06 01:09
使用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的操作已无意义了;
假如要跳到相同主机下,此语句后面的语句执行完成后才会跳转;
二. 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)
...
跳转后浏览器地址栏不变,但是只能跳到当前主机下
此语句后面的语句执行完成后才会跳转
- 比较JSP三种页面跳转方式
- JSP三种页面跳转方式的比较
- JSP三种页面跳转方式的比较
- JSP三种页面跳转方式的比较
- JSP三种页面跳转方式的比较
- JSP三种页面跳转方式的比较
- JSP三种页面跳转方式的比较
- JSP三种页面跳转方式的比较
- JSP三种页面跳转方式的比较
- jsp页面跳转三种方式的比较
- JSP三种页面跳转方式的比较
- JSP三种页面跳转方式的比较
- JSP三种页面跳转方式的比较
- JSP三种跳转方式的比较
- ASP三种页面跳转方式比较
- ASP.NET中页面跳转的三种方式比较
- JSP三种页面跳转方式
- JSP三种页面跳转方式
- java-05:笔记
- 路由配置与管理——OSPF路由配置与管理2
- google的只能指针scoped_refptr
- java提高篇(二三)-----HashMap
- Android 图片处理
- JSP三种页面跳转方式的比较
- linux作业-day 03
- Qt Quick Designer生成的图形可以自适应窗口的大小变化
- Smarty配置详解
- caffe 数据结构
- tomcat 启动异常,解决办法
- http请求
- umask遮罩法
- 关于Linux终端操作的快捷键