1、HTML:
①、
<head>
<!-- 以下方式只是刷新不跳转到其他页面 -->
<meta http-equiv="refresh" content="10">
<!-- 以下方式定时转到其他页面 -->
<meta http-equiv="refresh" content="5;url=hello.html">
</head>
2、javascript:
①、window.location.href方式
<script language="javascript" type="text/javascript">
// 以下方式直接跳转
window.location.href='hello.html';
// 以下方式定时跳转
setTimeout("javascript:location.href='hello.html'", 5000);
</script>
②、window.navigate方式跳转
<script language="javascript">
window.navigate("target.aspx");
</script>
③、window.loction.replace方式
<script language="javascript">
window.location.replace("target.aspx");
</script>
④、self.location方式
<script language="JavaScript">
self.location='target.aspx';
</script>
⑤、top.location方式
<script language="javascript">
top.location='target.aspx';
</script>
⑥、返回方式
<script language="javascript">
alert("返回");
window.history.back(-1);
</script>
PS:Javascript刷新页面的几种方法:
history.go(0)
location.reload()
location=location
location.assign(location)
document.execCommand('Refresh')
window.navigate(location)
location.replace(location)
document.URL=location.href
3、Java类(servlet):
①、response.sendRedirect("/a.jsp");
页面的路径是相对路径。sendRedirect可以将页面跳转到任何页面,不一定局限于本web应用中,如:
response.sendRedirect("http://www.jb51.net");
跳转后浏览器地址栏变化。
这种方式要传值出去的话,只能在url中带parameter或者放在session中,无法使用request.setAttribute来传递。
②、RequestDispatcher dispatcher = request.getRequestDispatcher("/a.jsp");
dispatcher .forward(request, response);
页面的路径是相对路径。forward方式只能跳转到本web应用中的页面上。
跳转后浏览器地址栏不会变化。
跳转到同级目录下的页面。
使用这种方式跳转,传值可以使用三种方法:url中带parameter,session,request.setAttribute
4、JSP:
①、response.sendRedirect();
同上。
②、response.setHeader("Location","");
此语句前不允许有out.flush(),如果有,页面不会跳转。
跳转后浏览器地址栏变化
此语句后面的语句执行完成后才会跳转
还木有评论哦,快来抢沙发吧~