Filter对Frame网页不起做用?
Spring, Struts, Hibernate, Tomcat
前段问过一个限制用户直接访问网页的问题,朋友们都建议说用Filter最合理,于是尝式了一下,果然不错,可是碰到一个问题,是这样的:
首先,用户通过登陆JSP页登陆系统,在登陆处理的Struts Action里面,我会把一个属性设置到session对象里面,用于标记用户已经登陆:
======================================================
HttpSession session = request.getSession();
session.setAttribute( "adminlogin ", "entered ");
在Filter实现的类中,对此属性进行判断:
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws
IOException,
ServletException {
//获取web.xml中配置的转向页面
String deniedPage = filterConfig.getInitParameter( "deniedPage ");
//获取session中adminlogin的值,如果没有设置此值,返回为null,说明未登录
String adminState = (String) request.getAttribute( "adminlogin ");
if(adminState==null)
{
((HttpServletResponse)response).sendRedirect(deniedPage);
}
else
{
chain.doFilter(request, response);
}
}
==================================================================
上面的方法对于处理单页面的直接访问有很好的效果,可是当我开发一个多页Frame的页面JSP时出现问题,这个adminmain页面如下:
<%@ page contentType= "text/html; charset=UTF-8 " %>
<%@ taglib uri= "/tags/struts-bean " prefix= "bean " %>
<%@ taglib uri= "/tags/struts-logic " prefix= "logic " %>
<%@ taglib uri= "/tags/struts-html " prefix= "html " %>
<%@ taglib uri= "/tags/struts-nested " prefix= "nested " %>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=UTF-8 "/>
<title> <bean:message key= "adminmainPage.title "/> </title>
<link href= "styles/project.css " rel= "stylesheet " type= "text/css ">
</head>
<frameset rows= "* " cols= "143,* " framespacing= "0 " frameborder= "NO " border= "0 ">
<frame src= "/project/dyn/admin/adminpanel.jsp " name= "leftFrame " scrolling= "No " noresize= "noresize " id= "leftFrame " title= "panel " />
<frame src= "/project/dyn/admin/adminworkspace.jsp " name= "mainFrame " id= "mainFrame " title= "workspace