在网上搜了一下,关于这个技术处理有多种方法,我只记下我在视频里学到的三种:
1、用一个response.sendredirect(目标页面.jsp\.htm);实现直接跳转;
2、有时我们需要有点提示,比如“x秒后自动跳转,若没有跳转,请点击此处”,则可以在myeclipse中调用snippets中的delay go to url.会自动生成如下代码:
[html]
<script language="javascript1.2" type="text/javascript">
<!--
// place this in the 'head' section of your page.
function delayurl(url, time) {
settimeout("top.location.href="http://www.php1.cn/"> }
//-->
</script>
<!-- place this in the 'body' section -->
<a href="http://www.php1.cn/"> 将此代码修改为:
[html] view plaincopy
<script language="javascript1.2" type="text/javascript">
function delayurl(url, time) {
settimeout(top.location.href=http://www.php1.cn/> }
</script>
<span id="time" style="background: red">3</span>
秒钟之后自动跳转,如果不跳转,请点击下面链接
<a href="http://www.php1.cn/"> <script type="text/javascript">
delayurl(目标页面.jsp, 3000);
</script>
然后将在3秒钟之后直接跳转到“目标页面”。这种方法就是设定几秒钟后跳转则在这过程中页面不会有变化,比如说设定3秒,然后随着时间的变化3变成2再变成1直至跳转,下面请看第三种方法。
3、把方法2中的代码修改为:
[html]
<script language="javascript1.2" type="text/javascript">
function delayurl(url) {
var delay=document.getelementbyid(time).innerhtml;
//最后的innerhtml不能丢,否则delay为一个对象
if(delay>0){
delay--;
document.getelementbyid(time).innerhtml=delay;
}else{
window.top.location.href=http://www.php1.cn/> }
settimeout(delayurl(' + url + '), 1000);
//此处1000毫秒即每一秒跳转一次
}
</script>
<span id="time" style="background: red">3</span>
秒钟之后自动跳转,如果不跳转,请点击下面链接
<a href="http://www.php1.cn/"> <script type="text/javascript">
delayurl(目标页面.jsp);
</script>
此方法实现的效果为在上一个页面点击完submit后跳转到本页面经过3秒(这个3会递减到0)后跳转到目标页面。
