(二十一):设置页面跳转 (JSP学习第六天)
2011-10-06 15:58
323 查看
设置页面跳转
使用response对象中的sendRedirect()方法进行跳转
直接跳转到hello.html页面 response_demo03.jsp
这种跳转属于客户端跳转
<jsp:forward>属于服务端跳转,地址不会发生改变,可以将request属性保存到跳转页
response.sendRedirect()属于客户端跳转,地址会发生改变,不可以将request属性保存到跳转页
还有一个区别就是:服务端跳转会立刻跳转,而客户端跳转在整个页面执行完后才进行跳转
服务器端跳转response_demo04.jsp
显示结果:hello
但tomcat服务器后台显示----------forward跳转之前的-------------
客户端跳转 response_demo05.jsp
tomcat服务器后台显示----------response跳转之前-------------
----------response跳转之后-------------
由于这两种跳转存在差异,所以在开发中,使用JDBC操作中,一定要再<jsp:forward>语句之
前关闭数据库的连接否则再也无法关闭,如果没有关闭,将达到一定程度时,则会出现数据库
已经达到最大的异常,此时就只有重启服务器了
使用<jsp:forward>,可以通过<jsp:param>进行参数传递
而使用response.sendRedirect()方式传递只有通过地址重写的方式传递
所以服务端跳转比客户端跳转更常用!
使用response对象中的sendRedirect()方法进行跳转
直接跳转到hello.html页面 response_demo03.jsp
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%> <html> <head> <title>测试</title> </head> <body> <% response.sendRedirect("hello.html"); %> </body> </html>
这种跳转属于客户端跳转
<jsp:forward>属于服务端跳转,地址不会发生改变,可以将request属性保存到跳转页
response.sendRedirect()属于客户端跳转,地址会发生改变,不可以将request属性保存到跳转页
还有一个区别就是:服务端跳转会立刻跳转,而客户端跳转在整个页面执行完后才进行跳转
服务器端跳转response_demo04.jsp
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%> <html> <head> <title>测试</title> </head> <body> <% System.out.println("----------forward跳转之前的-------------"); %> <jsp:forward page="hello.html"/> <% System.out.println("----------forward跳转之后的-------------"); %> </body> </html>
显示结果:hello
但tomcat服务器后台显示----------forward跳转之前的-------------
客户端跳转 response_demo05.jsp
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%> <html> <head> <title>测试</title> </head> <body> <% System.out.println("----------response跳转之前-------------"); %> <% response.sendRedirect("hello.html"); %> <% System.out.println("----------response跳转之后------------"); %> </body> </html>
tomcat服务器后台显示----------response跳转之前-------------
----------response跳转之后-------------
由于这两种跳转存在差异,所以在开发中,使用JDBC操作中,一定要再<jsp:forward>语句之
前关闭数据库的连接否则再也无法关闭,如果没有关闭,将达到一定程度时,则会出现数据库
已经达到最大的异常,此时就只有重启服务器了
使用<jsp:forward>,可以通过<jsp:param>进行参数传递
而使用response.sendRedirect()方式传递只有通过地址重写的方式传递
所以服务端跳转比客户端跳转更常用!
相关文章推荐
- 【学习摘记】马士兵Servlet&JSP_课时21_page_directive(编译期间执行的命令)——包的导入、错误跳转页面设置
- JSP设置自动跳转页面
- JSP页面跳转编码设置(Tomcat服务器)
- jsp学习之路之实现一个用户信息页面并实现跳转到另外一个页面输出用户的相关信息
- JSP的错误页面设置和页面跳转等
- 【学习摘记】马士兵Servlet&JSP_课时24_forward_sendredirect——原页面跳转 vs 新页面跳转
- myeclipse学习总结一(在MyEclipse中设置生成jsp页面时默认编码为utf-8编码)
- (六):设置页面的MIME (jsp学习第一天)
- JSP的错误页面设置和页面跳转等
- (七):设置页面编码 (JSP学习第一天)
- JSP学习总结:网络错误、传递空值、页面跳转、Attribute与Parameter的区别
- iOS 开发判断应用是否连接WiFi,并跳转到设置中的WiFi设置页面。
- 在jsp页面利用函数触发事件,根据dom元素的值来设置另一个dom元素的值
- JSP页面的五种跳转方法
- 五种JSP页面跳转方法--转别人的,有些心得
- SpringBoot支持JSP页面跳转(基于Gradle)
- Struts2中action重定向跳转到jsp页面两种配置方式
- storyBoard学习教程二(页面跳转)
- 5种jsp页面跳转
- JSP页面跳转