五种JSP页面跳转方法详解

1. RequestDispatcher.forward()

  是在服务器端起作用,当使用forward()时,Servlet engine传递HTTP请求从当前的Servlet or JSP到另外一个Servlet,JSP 或普通HTML文件,也即你的form提交至a.jsp,在a.jsp用到了forward()重定向至b.jsp,此时form提交的所有信息在 b.jsp都可以获得,参数自动传递. 但forward()无法重定向至有frame的jsp文件,可以重定向至有frame的html文件,同时forward()无法在后面带参数传递,比如servlet?name=frank,这样不行,可以程序内通过response.setAttribute("name",name)来传至下一个页面。

  重定向后浏览器地址栏URL不变。

  例:在servlet中进行重定向

public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
  response.setContentType("text/html; charset=gb2312");
  ServletContext sc = getServletContext();
  RequestDispatcher rd = null;
  rd = sc.getRequestDispatcher("/index.jsp"); //定向的页面
  rd.forward(request, response);
}

  通常在servlet中使用,不在jsp中使用。

  2. response.sendRedirect()

  是在用户的浏览器端工作,sendRedirect()可以带参数传递,比如servlet?name=frank传至下个页面,同时它可以重定向至不同的主机上,sendRedirect()可以重定向有frame.的jsp文件.

  重定向后在浏览器地址栏上会出现重定向页面的URL

  例:在servlet中重定向

public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
  response.setContentType("text/html; charset=gb2312");
  response.sendRedirect("/index.jsp");
}

  由于response是jsp页面中的隐含对象,故在jsp页面中可以用response.sendRedirect()直接实现重定位。

  注意:

  (1) 使用response.sendRedirect时,前面不能有HTML输出;

  这并不是绝对的,不能有HTML输出其实是指不能有HTML被送到了浏览器。事实上现在的server都有cache机制,一般在8K(我是说 JSP SERVER),这就意味着,除非你关闭了cache,或者你使用了out.flush()强制刷新,那么在使用sendRedirect之前,有少量的HTML输出也是允许的。

  (2) response.sendRedirect之后,应该紧跟一句return。

  我们已经知道response.sendRedirect是通过浏览器来做转向的,所以只有在页面处理完成后,才会有实际的动作。既然你已经要做转向了,那么后的输出还有什么意义呢?而且有可能会因为后面的输出导致转向失败。

  比较:

  (1) Dispatcher.forward()是容器中控制权的转向,在客户端浏览器地址栏中不会显示出转向后的地址;

  (2) response.sendRedirect()则是完全的跳转,浏览器将会得到跳转的地址,并重新发送请求链接。这样,从浏览器的地址栏中可以看到跳转后的链接地址。

  前者更加高效,在前者可以满足需要时,尽量使用RequestDispatcher.forward()方法。

  注:在有些情况下,比如,需要跳转到一个其它服务器上的资源,则必须使用HttpServletResponse.sendRequest()方法。

  3. <jsp:forward page="" />

  它的底层部分是由RequestDispatcher来实现的,因此它带有RequestDispatcher.forward()方法的印记。

  如果在之前有很多输出,前面的输出已使缓冲区满,将自动输出到客户端,那么该语句将不起作用,这一点应该特别注意。

  另外要注意:它不能改变浏览器地址,刷新的话会导致重复提交

  4. 修改HTTP header的Location属性来重定向

  通过设置直接修改地址栏来实现页面的重定向。

  jsp文件代码如下:

<%
 response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
 String newLocn = "/newpath/jsa.jsp";
 response.setHeader("Location",newLocn);
%>


  5. JSP中实现在某页面停留若干秒后,自动重定向到另一页面

  在html文件中,下面的代码:

<meta http-equiv="refresh" content="300; url=target.jsp">

  它的含义:在5分钟之后正在浏览的页面将会自动变为target.html这一页。代码中300为刷新的延迟时间,以秒为单位。targer.html为你想转向的目标页,若为本页则为自动刷新本页。

  由上可知,可以通过setHeader来实现某页面停留若干秒后,自动重定向到另一页面。

  关键代码:

String content=stayTime+";URL="+URL;
response.setHeader("REFRESH",content);
SpringBoot+Thymeleaf跳转的简单实例 SpringBoot笔记(二)---- SpringBoot整合Thymeleaf模板 博客源码 立即下载

相关推荐

javascript 页面跳转方法集合

js 中实现页面跳转的方法[removed]和window.open的区别)

JSP跳转方式

一:RequestDispatcher.forward()        是在服务器端起作用,当使用forward()时,Servlet engine 传递HTTP请求从当前的Servlet  or jsp  到另外一个Servlet JSP 或普通HTML文件        可以进行参数传递 如: RequestDispatcher rd = context.getRequestDispa

itmyhome的专栏 5万+

器件物理与工艺:揭秘MOSFET寄生电容Cgd/Cgs的微观结构及演变

本文深入解析MOSFET寄生电容Cgd与Cgs的微观物理结构及其在开关过程中的非线性演变,重点探讨由Cgd反馈效应引发的米勒平台现象。通过分析器件物理机制与先进工艺技术,揭示电容特性对开关性能的影响,并提供工艺优化与设计策略,助力提升高频功率应用的效率与稳定性。

desk3的博客 1089

html页面自动跳转链接3种方法

方法1: <meta http-equiv="refresh" content="3;URL=www.wulangwang.top/"> 方法2: <script type="text/javascript"> window.onload=function(){ setTimeout(g...

张成的博客2017-2020 2万+

Cadence 17.2配置CIS数据库报错?手把手解决ODBC驱动位数不匹配问题

本文详细解析了Cadence 17.2配置CIS数据库时常见的ODBC驱动位数不匹配问题,提供了从系统环境检查到分步解决方案的完整指南。重点解决32位应用程序与64位ODBC驱动之间的架构冲突,包含驱动安装、DSN配置及高级排查技巧,帮助电子工程师快速恢复设计环境。

play7的博客 983

Win11下Python脚本不执行?5分钟搞定PATH环境变量配置(VSCode终端实测)

本文针对Win11系统下VSCode终端中Python脚本执行无响应的问题,提供了详细的诊断与解决方案。核心在于正确配置PATH环境变量,通过图形化界面调整Python路径优先级,并分享了VSCode终端环境变量的刷新技巧,帮助开发者在5分钟内快速解决环境配置难题。

weixin_28358083的博客 399

jsp跳转到本身页面_五种JSP页面跳转方法详解

1. RequestDispatcher.forward()是在服务器端起作用,当使用forward()时,Servlet engine传递HTTP请求从当前的Servlet or JSP到另外一个Servlet,JSP 或普通HTML文件,也即你的form提交至a.jsp,在a.jsp用到了forward()重定向至b.jsp,此时form提交的所有信息在 b.jsp都可以获得,参数自动传递. ...

weixin_42638178的博客 2378

FineReport V11.0安装避坑指南:从下载到激活的完整流程(附百度网盘链接)

本文提供FineReport V11.0从下载、安装到激活的完整避坑指南。详细解析了部署前的环境准备、安装过程中的JVM内存等核心配置、激活流程以及安装后的优化与常见问题排查,旨在帮助用户一次部署成功,确保企业级报表平台的稳定运行。

echo99的专栏 1213

jsp转发跳转页面_五种JSP页面跳转方法详解

1. RequestDispatcher.forward()是在服务器端起作用,当使用forward()时,Servlet engine传递HTTP请求从当前的Servlet or JSP到另外一个Servlet,JSP 或普通HTML文件,也即你的form提交至a.jsp,在a.jsp用到了forward()重定向至b.jsp,此时form提交的所有信息在 b.jsp都可以获得,参数自动传递. ...

weixin_32894769的博客 2736

增量编码器资讯大全

增量编码器是什么 增量式编码器是将位移转换成周期性的电信号,再把这个电信号转变成计数脉冲,用脉冲的个数表示位移的大小,按照工作原理编码器可分为增量式和绝对式两类。 增量式编码器是将位移转换成周期性的电信号,再把这个电信号转变成计数脉冲,用脉冲的个数表示位移的大小。 编码器是把角位移或直线位移转换成电信号的一种装置。前者称为码盘,后者称码尺.按照读出方式编码器可以分为接触式和非接触式两种.接触式采...

kindele的博客 6018

DESeq2实战:利用LRT检验解析时间序列基因表达动态变化

本文详细介绍了如何使用DESeq2中的LRT检验分析时间序列基因表达数据,揭示基因表达动态变化模式。通过构建完整模型与简化模型比较,LRT检验能有效识别处理效应随时间变化的基因,适用于发育过程、疾病进展等研究。文章提供了从数据准备、模型构建到结果可视化的完整实战指南,并分享了高级技巧与常见问题排查方法。

weixin_29062671的博客 470

五种 JSP页面跳转方法详解

五种 JSP页面跳转方法详解 时间:2012-09-04   作者:huhao1989   出处:huhao1989.iteye.com 本文向您介绍Servlet页面跳转实现方法的几种区别,包括Servlet和JSP中的不同实现,比如Servlet中的redirect方式和forward方式得区别等。 1. RequestDispatcher.forward() 

evilcry2012的专栏 463

长鑫存储面试真题解析:DRAM工程师的工程直觉与产线思维

DRAM作为现代计算系统的底层存储基石,其性能与可靠性高度依赖半导体物理基础、工艺窗口控制和电路-系统协同设计。理解电荷保持机制、位线电容耦合效应、信号完整性约束等核心原理,是突破传统数字IC思维、构建真实产线语感的关键。在晶圆厂级工程实践中,TEM缺陷识别、BIST空间聚类分析、Retention失效定位等能力,直接关联良率爬坡与客户系统稳定性。本文聚焦长鑫存储一线技术面试中高频出现的工艺-电路-测试三维问题,融合‘电荷保持’‘信号完整性’等热词,还原DRAM工程师必备的系统性建模能力与闭环验证思维,覆盖

weixin_34293246的博客 345

jsp子窗口是php页面跳转,五种 JSP页面跳转方法详解

五种 JSP页面跳转方法详解更新时间:2009年04月09日 11:41:57 作者:jsp实现页面跳转的实现代码,五种方法,大家可以根据需要选择。1. RequestDispatcher.forward()是在服务器端起作用,当使用forward()时,Servlet engine传递HTTP请求从当前的Servlet or JSP到另外一个Servlet,JSP 或普通HTML文件,也即你...

weixin_28716973的博客 168

SOEM主站开发篇(1):移植SOEM主站到Linux开发板

详细介绍了SOEM主站源码移植到Linux开发板上的步骤,同时演示了如何使用Linux开发板获取EtherCAT从站的PDO映射信息。

kevin1499的博客 2405

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

jsp页面的五种跳转方法详解

五种JSP页面跳转方法详解2009-07-20 09:00 1. RequestDispatcher.forward() 是在服务器端起作用,当使用forward()时,Servlet engine传递HTTP请求从当前的Servlet or JSP到另外一个Servlet,JSP 或普通HTML文件,也即你的form提交至a.jsp,在a.jsp用到了fo...

weixin_33860553的博客 204

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: html css简单知识点
下一篇: JavaScript倒计时自动跳转
danwind
博客等级 码龄19年 6粉丝 118原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值