使用response.sendRedirect的注意事项。
来源:互联网 发布:js单独一个文件怎么写 编辑:程序博客网 时间:2024/04/27 19:31
转自:http://www.newasp.net/tech/53042.html
首先我们要明白用response.sendRedirect做转向的原理,它其实是向浏览器发送一个特殊的Header,然后由浏览器来做转向,转到指定的页面,所以用sendRedirect时,浏览器的地址栏上可以看到地址的变化。
用<jsp:forward page=""/>则不同,它是直接在server做的,浏览器并不知道,也不和浏览器打交道,这从浏览器的地址并不变化可以看出。所以使用response.sendRedirect时就需要注意以下两点:
1,在使用response.sendRedirect时,前面不能有HTML输出。
这并不是绝对的,不能有HTML输出其实是指不能有HTML被送到了浏览器。事实上现在的server都有cache机制,一般在8K(我是说JSP SERVER),这就意味着,除非你关闭了cache,或者你使用了out.flush()强制刷新,那么在使用sendRedirect之前,有少量的HTML输出也是允许的。
如果报错说,“一些信息已经被submitted”(原文忘了),那么,你就要注意看了,前面是不是有过多的HTML输出了。
2,在response.sendRedirect之后,应该紧跟一句return;
我们已经知道response.sendRedirect是通过浏览器来做转向的,所以只有在页面处理完成后,才会有实际的动作。既然你已经要做转向了,那么后的输出还有什么意义呢?而且有可能会因为后面的输出导致转向失败。
阅读全文
0 0
- 使用response.sendRedirect的注意事项。
- response.sendRedirect的注意事项
- response.sendRedirect()使用注意事项
- response.sendRedirect()使用注意事项
- response.sendRedirect的使用
- response.sendRedirect的使用
- response.sendRedirect() 跳转时的注意事项
- jsp跳转response.sendRedirect的注意事项
- 使用response.sendRedirect的注意点
- 使用response.sendRedirect()时的中文问题
- iframe和response.sendRedirect使用的问题
- iframe和response.sendRedirect使用的问题
- iframe和response.sendRedirect使用的问题
- iframe和response.sendRedirect使用的问题
- response.sendRedirect使用须知
- response.sendRedirect和html frame配合使用的问题
- response.sendRedirect和html frame配合使用的问题
- servlet如何选择request.getRequestDispatcher和response.sendRedirect的使用
- enable_shared_from_this解析
- 【数学结论】51Nod 1674 区间的价值 V2
- ubunt和Windows共享目录设置备份
- Python中如何调用Linux命令
- 数据结构第二周项目--C/C++语言中函数传递的三种方式
- 使用response.sendRedirect的注意事项。
- spring集成mybatis后,打印SQL语句
- web项目中,在web.xml中配置全局变量
- 安装Cocoapods详细教程
- mac 问题处理
- LaTex技巧(五):如何在图形的右方插入统计表格呢?
- Unity-Rigidbody【刚体】组件-Collision Detection碰撞检测模式
- 4321: queue2
- 小希的迷宫.