1、HTML:
①、
2、javascript:
①、window.location.href方式
//以下方式直接跳转
window.location.href='hello.html';//以下方式定时跳转
setTimeout("javascript:location.href='hello.html'",5000);
②、window.navigate方式跳转
window.navigate("target.aspx");
③、window.loction.replace方式
window.location.replace("target.aspx");
④、self.location方式
self.location='target.aspx';
⑤、top.location方式
top.location='target.aspx';
⑥、返回方式
alert("返回");
window.history.back(-1);
PS:Javascript刷新页面的几种方法: history.go(0)location.reload()location=locationlocation.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(),如果有,页面不会跳转。
跳转后浏览器地址栏变化
此语句后面的语句执行完成后才会跳转