对IFrame,如何使mapping.findForward指向的页面成为当前主页面?

eHuaTian 2009-04-13 04:21:02
主页面内嵌入一个IFrame,IFrame内有一个按钮,点击此按钮,执行Struts的一个Action,Action执行完成后使用mapping.findForward进入一个新的页面。如果不作处理,进入的新页面仍处于IFrame内,主页面的其他区域内容仍在当前页面上,没有变化。现在要使mapping.findForward所指向的页面成为当前主页面,如何做呢?
...全文
167 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovingpig 2009-04-14
  • 打赏
  • 举报
回复
在你的页面上加上
<script>
window.name="mywindow";
</script>

你iframe里面也肯定是用form递交的吧
只要在那个form上再加一个属性 target

<form action="" method="post" target="mywindow">
</form>

这样在你这个form递交的时候就会刷新名称为mywindow的窗口
lovingpig 2009-04-14
  • 打赏
  • 举报
回复
晕 不知道你怎么试的

我这边有个例子
你看下:
iframe.jsp
<%@ include file="/WEB-INF/jsp/include.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<link rel="stylesheet" href="<%=basePath%>css/homefinancial.css" type="text/css">
<script src="<%=basePath%>include/homeFinancial.js" language="javascript"></script>
<html:form action="addConsumeAction.do?method=add" method="post" target="mainwindow">
<table>
<tr><td>Consumer: </td><td><html:text property="name"></html:text></td></tr>
<tr><td>amount: </td><td><html:text property="amount"></html:text></td></tr>
<tr><td>Description: </td><td><html:text property="description"></html:text></td></tr>
<tr><td>Date: </td><td><html:text property="date"></html:text></td></tr>
<tr><td><input type="button" value="add" onclick="addConsumeFormSubmit();"></input></td></tr>
</table>
</html:form>


homeFinancial.jsp

<%@ include file="/WEB-INF/jsp/include.jsp" %>
<%@ taglib prefix="spring" uri="/spring" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><fmt:message key="login.title"/></title>
</head>
<link rel="stylesheet" href="<%=basePath%>css/homefinancial.css" type="text/css">
<script src="<%=basePath%>include/homeFinancial.js" language="javascript"></script>
<script>
window.name="mainwindow";
</script>

<body>

<h1>Successful</h1>

<logic:notEmpty name="consumes">
<table border="0" cellspacing="0" cellpadding="0" class="mytable" id="tableForRecValue">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Amount</th>
<th>Description</th>
<th>Date</th>
</tr>
</thead>
<c:forEach items="${consumes}" var="consume" varStatus="status">
<tr>
<td><c:out value="${status.index + 1}"/></td>
<td><c:out value="${consume.name}"/></td>
<td><c:out value="${consume.number}"/></td>
<td><c:out value="${consume.description}"/></td>
<td><c:out value="${consume.date}"/></td>
</tr>
</c:forEach>
</table>
<table>
<c:if test="${pageNumber > 1}">
<tr>
<td><c:out value="${currentPage}"/>/<c:out value="${pageNumber}"/></td>
<c:if test="${currentPage > 1}">
<td><a href="homeFinancialAction.do?method=list&page=<c:out value="${prePage}"/>">pre</a></td>
</c:if>
<c:if test="${currentPage < pageNumber}">
<td><a href="homeFinancialAction.do?method=list&page=<c:out value="${nextPage}"/>">next</a></td>
</c:if>
</tr>
</c:if>
</table>
</logic:notEmpty>
<logic:empty name="consumes">
<table>
<tr><td><fmt:message key="homefinancial.no.consume"/></td></tr>
</table>
</logic:empty>
<IFRAME name="iframe" SCROLLING="yes" src="jsp/iframe.jsp" width="100%" height="100%" id="page2"></IFRAME>

</body>
</html>
eHuaTian 2009-04-14
  • 打赏
  • 举报
回复
谢谢!能不能来段完整的代码好参考一下。我是刚学jsp
eHuaTian 2009-04-14
  • 打赏
  • 举报
回复
谢谢lovingpig等的回答。我按lovingpig的方法试过,还是不行丫。Action的mapping.findForward所指向的页面仍然在IFrame内。现在要使mapping.findForward所指向的页面为当前主页面,有没有其他计算方法了?
lovingpig 2009-04-13
  • 打赏
  • 举报
回复
你在主页面上用javascript设置 窗口名称
window.name="mywindow";

再把你的form中的target 设置成 mywindow

<form action="" target="mywindow">
</form>

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧