解决session过期跳转到登陆页面并跳出iframe框架

/**
 * 访问控制过滤器
 */
package com.lz.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lz.pojo.Userinfo;
import com.lz.util.DefaultElements;

/**
 * @author zxj
 * @version 9:47:52 AM Jan 11, 2011
 */
public class AccessFilter implements Filter {

 public static String loginurl;
 public static String errorurl;

 /* (non-Javadoc)
  * @see javax.servlet.Filter#destroy()
  */
 
 public void destroy() {
  // TODO Auto-generated method stub

 }

 
 public void doFilter(ServletRequest arg0, ServletResponse arg1,
   FilterChain arg2) throws IOException, ServletException {
  // TODO Auto-generated method stub
  HttpServletRequest request = (HttpServletRequest) arg0;
  HttpServletResponse response = (HttpServletResponse) arg1;
 
  Userinfo user = (Userinfo) request.getSession().getAttribute("user");
 
  
  if (user == null) {
   response.sendRedirect(DefaultElements.LOGINURL);
   return;
  }
  arg2.doFilter(request, response);
 }

 public void init(FilterConfig arg0) throws ServletException {
 }

}

 

但是这样不能不能跳出iframe等框架。

可以用javaScript解决
在你想控制跳转的页面,比如login.jsp中的与之间加入以下代码:

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(开发技术)