jsp或servlet中有哪几种跳转方式。它们有何区别

来源:互联网 发布:数据库物理层 编辑:程序博客网 时间:2024/06/05 04:15

1.客户端跳转:
1).使用form表单的action属性设置要跳转的页面(此方法可以将此页面的form表单属性值传递到下一页面):如下
<form action="my.jsp" name="lili" onsubmit="return test()">
<input type="submit" value=http://www.hake.cc/a/biancheng//"提交">
或者(button类型需要手动提交表单):
<input type="button" value=http://www.hake.cc/a/biancheng/"注册" onclick="test()">
javascript的函数:
function test(){
    //手动设置跳转页面
     document.lili.action="my1.jsp";
    document.lili.submit();
}
2).使用javascript中的页面跳转的方法(不能将form表单中的属性值传递到下一页面):
window.location.href=http://www.hake.cc/a/biancheng//"my.jsp";
window.location.replace("my.jsq");//此方法不可将页面后退.
2.服务端跳转的两种方法对比:
<jsp:forward page="xxx.jsp"/>:等价于
request.getRequestDispatcher("xxx.jsp").forward(request,response);
本服务器的资源跳转,效率更高.地址栏不改变(仍为跳转前的页面).可得到request属性值.
response.sendRedirect("xxx.jsp"):
重定向到任意资源.地址栏改为当前页面.无法得到request属性值.
 

0 0
原创粉丝点击