最近做项目时,学到了几种jsp页面跳转方式,整理如下:
1、以模态窗口的形式进行跳转
1)设计好需要跳转到的子页面,children.jsp
2)在父页面中定义一个div,准备放置子页面
<div id="childrenDiv" >
</div>
//定义按钮,点击此按钮时打开模态窗口
<input id="childrenButton" type="button" value="打开窗口">
3)在父页面的js中定义个触发事件,打开模态窗口:
$("#childrenButton").click(function() {
$.ajax({
type:"post",
//执行action,返回子页面(children.jsp)
url: contextPath + "searchChildrenAC!refreshChilren.do",
dataType:"html",
success:function(html){
//将子页面放到父页面的div中
$("#childrenDiv").empty();
$("#childrenDiv").html(html);
//将放置子页面的div定义为模态窗口
var childrenWindow = $("#childrenDiv").createWindow({
title : "新窗口",
top : '20%',
left : '22%',
width : 780,
height : 300,
modal : true,
close : function() {
//模态窗口关闭时的回调函数
}
});
//显示模态窗口
medicineTableItemWindow.showWindow();
},
error:function(){
}
});
});
2、以弹出窗口形式跳转
1)设计好需要跳转到的子页面,children.jsp
2)在父页面中写一个<form/>表单
//提交该form表单,能够跳转到children.jsp
<form id="openChildrenForm" action="search/searchChildrenAC!refreshChildren.do" method="post" target="childrenPage"></form>
//定义按钮,点击此按钮时打开新窗口
<input id="childrenButton" type="button" value="打开窗口">
3)在父页面的js中定义触发事件,打开新窗口
$("#childrenButton").click(function() { var itop = (window.screen.availHeight - 634) / 2; var ileft = (window.screen.availWidth - 1200) / 2; var atPage = window .open( '', "childrenPage",//form表单中的target属性,必须和这个值相同 "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,"+
"resizable=0,copyhistory=0,width=1200,height=693,"+
"left="+ ileft + ",top=" + itop
); $('#openChildrenForm').submit(); atPage.focus(); }