子窗口提交后关闭,父窗口刷新

本文介绍了一个使用Java实现的父窗口与子窗口交互的例子,包括弹出子窗口、子窗口返回值给父窗口并刷新数据列表等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

父窗口页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setAttribute("path",path);
request.setAttribute("basePath",basePath);
%><html>
<head>
<!--aa.jsp-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" CONTENT="no-cache">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Expires" CONTENT="-1">
<title>父窗口</title>
<link href="${path}/css/common.css" rel=stylesheet type="text/css">
<link href="${path}/css/table.css" rel=stylesheet type="text/css">
<link href="${path}/css/content.css" rel=stylesheet type="text/css">
<script language="javascript">
function gotoPage(butType)
{
var src = "";
switch(type)
{
case "search":
src= "${path}yy.do?条件";
break;
case "add":
[color=red]//弹出父窗口,如果子窗口需要url,则url在此是实际的获得数据的路径[/color]
var winFrame=window.showModalDialog("bb.jsp", "winFrame", 'dialogWidth:500px; dialogHeight:300px; center:yes; resizable:no; status:no; help:no;');
[color=red]//判断从子窗口返回值,如果是1,刷新父窗口(重新提交)[/color]
if(winFrame==1){
[color=red] //重新提交(也就是重新加载数据列表)[/color]
src= "${path}yy.do?条件";
$("framePage").src = src;
}
break;
}
$("framePage").src = src;
}
</script>
</head>

<body id="content_body" scroll="no" >
<form>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="3" align="left" valign="middle">

<table width="900" height="24" cellpadding="0" cellspacing="0" onDblClick="hideSearchPanel();" id="tool_bar">
<tr>
<td>
<input type="button" name="检索" value="检索数据" onClick="gotoPage('search')"/>
</td>
</tr>
<tr>
<td>
<!--数据列表-->
</td>
</tr>
<tr>
<td width="5"></td>
<td >
<input type="button" name="button" value="弹出子窗口" onClick="gotoPage('add');" style="width: 80px;"/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" valign="middle" >
<iframe id="framePage" name="framePage" src="${path}yy.do" height="100%" width="100%" scrolling="auto" frameborder="1" border="1">
</td>
</tr>
</table>
</form>
</body>
</html>

子窗口页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setAttribute("path",path);
request.setAttribute("basePath",basePath);
%>
<html>
<head>
[color=red]<!--bb.jsp子窗口-->
<!--base 和title是必须的,而且必须放在这个位置-->
<base target="_self">
<title>子窗口名称</title>[/color]
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" CONTENT="no-cache">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Expires" CONTENT="-1">
<script type="text/javascript" src="${path}/js/jquery-1.4.2.min.js"></script>
<script language="javascript">

function add(){
src="${path}xxx.do";
[color=red] //在此的action路径,返回页面为本身页面[/color]
frm.action=src;
frm.submit();
[color=red]//提交完毕关闭本身页面[/color]
window.close();
}
</script>
</head>

<body>
<script>
[color=red]//向父窗口返回一个标志,在父窗口判断,如果为1就刷新[/color]
window.returnValue=1;
</script>
<form action="" name="frm" id="frm">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<input type="button" name="button" value="添加数据" onClick="add();"/>
</td>
</tr>
</table>
</form>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值