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(),如果有,页面不会跳转。

跳转后浏览器地址栏变化

此语句后面的语句执行完成后才会跳转

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐