servlet跳转到frameset框架外

来源:互联网 发布:数据库用户老是被锁 编辑:程序博客网 时间:2024/06/06 04:19

在用servlet进行跳转时,遇到了框架问题。

index.jsp页面是由上、左、右三部分组成,由index.jsp跳转到servlet后,想直接跳到login.jsp页面,而login.jsp页面是不带框架的。

在跳转时就有可能还在框架内跳转。

先看index.jsp页面:

<span style="font-size:18px;"><frameset name="all" border=0 frameSpacing=0 rows="55, *" frameBorder=0><frame name="header" src="JSP/header.jsp"  frameBorder=0 noResize scrolling=no />    <frameset cols="210, *">    <frame name="side" src="JSP/side.jsp" frameBorder=0 noResize scrolling=yes>    <frame name="main" src="JSP/main.jsp" frameBorder=0 noResize scrolling=yes>    </frameset></frameset></span>

具体跳转情况如下:

从index.jsp页面中的header.jsp跳转到servlet,然后从servlet跳转到login.jsp。

解决办法如下:

先从header.jsp页面跳转到servlet页面,没有问题,然后从servlet页面跳转到中间页面test.jsp,然后由test.jsp触发onload事件,跳转到login.jsp页面。

其实最主要的还是onload事件怎么写的问题,代码如下:

<span style="font-size:18px;"><%@ page language="java" import="java.util.*" pageEncoding="GB18030"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>test page</title>    <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><script>function load(){parent.location.href="/CSMS/JSP/login.jsp"}</script>  </head>  <body onload="load()">  </body></html></span>

这里的跳转用到的是parent.location.href,只有这样才能跳到框架外面。


说了半天,其实解决办法就一条代码:

parent.location.href="/CSMS/JSP/login.jsp"


这才是核心代码。






0 0
原创粉丝点击