教程集 www.jiaochengji.com
教程集 >  脚本编程  >  java  >  正文 jsp sendRedirect()方法进行跳转详解

jsp sendRedirect()方法进行跳转详解

发布时间:2017-12-09   编辑:jiaochengji.com
教程集为您提供jsp sendRedirect()方法进行跳转详解等资源,欢迎您收藏本站,我们将为您提供最新的jsp sendRedirect()方法进行跳转详解资源
在使用response对象中的sendRedirect()方法进行跳转,使用response.sendRedirect()方式传递只有通过地址重写的方式传递 所以服务端跳转比客户端跳转更常用!

直接跳转到hello.html页面 response_demo03.request属性保存到跳转页
response.sendRedirect()属于客户端跳转,地址会发生改变,不可以将request属性保存到跳转页
还有一个区别就是:服务端跳转会立刻跳转,而客户端跳转在整个页面执行完后才进行跳转

服务器端跳转response_demo04.jsp

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5783')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5783>

<%@ 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跳转之前的-------------

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7519')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7519>

客户端跳转 response_demo05.jsp

view sourceprint?<%@ 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跳转之后-------------

您可能感兴趣的文章:
jsp sendRedirect()方法进行跳转详解
servlet与jsp基础教程(8)-设置HTTP应答头
php和jsp之间有哪些区别
Struts2处理结果的学习笔记
JSP常见问题
php如何实现页面跳转
PHP 登录完成跳转上一访问页面
Jquery实现网页跳转或用命令打开指定网页的解决方法
PHP实现301跳转,及延时跳转代码
servlet与jsp基础教程(7)-HTTP应答状态

[关闭]
~ ~