日期:2014-05-16  浏览次数:20462 次

JSP页面定时自动跳转的实现(转)

?? 1.登陆后自动跳转到登陆前的那一页,因此必须先取得那一页的URL并且传到登陆页去,在页面间穿参数有很多种方法,这里选用的是重写URL方法。
???? 取得当前页的URL:
??? <%
???? String url=request.getScheme()+"://";
???? url+=request.getHeader("host");
???? url+=request.getRequestURI();
?? if(request.getQueryString()!=null)
???? url+="?"+request.getQueryString();
??? %>
???? 注意:再取的该URL时不仅仅是取到当前页面的URL值,还应该把“?”后面的参数一并取过来,这样才能保证之前的页面在以后能正常访问。
???? 重写URL传参:
??? <a href=login.jsp?url="+url+">登陆</a>

???? 2。登陆页获取参数:
??? <%??? String urlstring = request.getParameter("url") ;%>
???? 登陆表单:
?? <form method="post" name="login" action="login.jsp">
??? ?? ??? ??? <input name="action" value="login" type="hidden">
??? ?? ??? ??? <p>
??? ?? ??? ??? ??? &nbsp;用户名:
??? ?? ??? ??? ??? <input type="text" name="username">
??? ?? ??? ??? </p>
??? ?? ??? ??? <p>
??? ?? ??? ??? ??? 密码:
??? ?? ??? ??? ??? <input type="password" name="password">
??? ?? ??? ??? ??? <br>
??? ?? ??? ??? ??? <input?? type="hidden"?? name="url" value="<%=urlstring %>">?? //暂存url,然后再传到当前页
??? ?? ??? ??? </p>
??? ?? ??? ??? <p>
??? ?? ??? ??? ??? &nbsp;
??? ?? ??? ??? ??? <input type="submit" value="登录" name="submit">
??? ?? ??? ??? ??? <input type="reset" value="重置" name="reset">
??? ?? ??? ??? ??? <br>
??? ?? ??? ??? </p>
??? ?? ??? ??? <p>
??? ?? ??? ??? ??? &nbsp;
??? ?? ??? ??? </p>
??? ?? ??? </form>
??? 3。登陆成功后的跳转:
??? <span id="time" style="background:red">5</span>秒钟后自动跳转,如果不跳转,请点击下面链接
??? ??? <script language="JavaScript1.2" type="text/javascript">
??? ??? ??? <!--
??? ??? ??? function delayURL(url) {?????????????? //定时跳转
??? ?? ?? var delay = document.getElementById("time").innerHTML;
??? ??? ??? if(delay > 0) {
??? ??? ??? delay--;
??? ??? ??? document.getElementById("time").innerHTML = delay;
?? ?? ??? } else {
?? ?? ??? ??? window.top.location.href = url;
?? ?? ??? ??? }
?? ?? ??? setTimeout("delayURL('" + url + "')", 1000);
??? ??? }
??? ??? //-->
??? </script>
??? <a href="<%=urlstring%>">返回</a>
??? <script type="text/javascript">
??? delayURL("<%=urlstring%>");
??? </script>???