java页面跳转保留iframe

Python016

java页面跳转保留iframe,第1张

1、使用filter过滤用户是否登录或者是否有非法字符,如果用户没有登陆或有非法字符则转向登陆页面,这时候可以使用response.sendRedirect(跳转地址)。

2、发现被重定向的只是父页面中的iframe区域,登陆页面内容显示在iframe区域中,说明在过滤器中发送重定向请求时,是在iframe页面发送的。

3、要在servlet中获取字符打印流前面设置编码。

假如有两个frame,分别为frame1,frame2,frame1加个按钮实现跳转.frame1代码如下

import java.awt.event.ActionEvent

import java.awt.event.ActionListener

import javax.swing.JButton

import javax.swing.JFrame

public class frame1 extends JFrame implements ActionListener{

/**

* @param args

*/

private JButton jb

public frame1()

{

this.setSize(300, 200)

this.setLocation(300, 400)

jb=new JButton("跳转")

this.add(jb)

jb.addActionListener(this)//加入事件监听

this.setVisible(true)

}

public static void main(String[] args) {

// TODO Auto-generated method stub

frame1 frame=new frame1()

}

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

if(e.getSource()==jb)

{

this.dispose()//点击按钮时frame1销毁,new一个frame2

new frame2()

}

}

}

frame2是个单纯的界面

import javax.swing.JButton

import javax.swing.JFrame

public class frame2 extends JFrame{

/**

* @param args

*/

public frame2()

{

this.setSize(300, 200)

this.setLocation(300, 400)

this.setVisible(true)

}

public static void main(String[] args) {

// TODO Auto-generated method stub

frame2 frame=new frame2()

}

}

java程序中的jsp页面点击按钮跳转到页面b的方式如下:

1.jsp页面的方式如下:<a href="....b.jsp">跳转</a>

response.sendRedirect("b.jsp")

<jsp:forward page="b.jsp"/>

2.在swing里,给button加一个监听器,然后在监听事件中打开另一个页面。

在jsp或是静态网页里,onclick=“JavaScript:window.location=’xx‘”