ûỰ��� ������ת����ҳ��
1 web.xml м filter���� � ������
<filter>
<filter-name>SessionFilter</filter-name>//�������
<filter-class>com.zhsd.sms.common.util.SessionFilter</filter-class>//
Ŀ еĹ�� � �����
<init-param>// ʼ һ�� �� �����
<param-name>noFilter</param-name>// ƣ������ ��ڹ������л��
<param-
value>index.action,index.jsp,seekPwd.jsp,login.jsp,logout.action,userPwdSeek.act
ion,progressbar.html,loginAjax.action</param-value>//��� � ����������ֵ ҳ��
</init-param>
<init-param>// ʼ�� �ڶ������
<param-name>past</param-name>// ƣ������ ��ڹ������л��
<param-value>sessionPast.jsp</param-value>//�����ֵΪ������ת��ҳ��
</init-param>
</filter>
<filter-mapping>
<filter-name>SessionFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>SessionFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
2 session ʱ������ ���� ��
<session-config>��
<session-timeout>30</session-timeout>
</session-config>
3 д SessionFilter�� ������ ��
public class SessionFilter implements Filter {
public FilterConfig config;
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpreq = (HttpServletRequest)
request;// request����
HttpServletResponse httpres = (HttpServletResponse)
response;// response����
String noFilter =
config.getInitParameter("noFilter");// web.xml ȡ ò ˵�� �� � ���� ��ֵ
String past = config.getInitParameter("past");// ȡ ù�� ��� �����ת��ҳ��
String uri = httpreq.getRequestURI();// ȡ ·�� ������ ��
String context = httpreq.getContextPath();// ȡ Ŀ· ·�� �� ���� ��
if (!uri.equals(context + "/")// ȡ õ · ƥ�� � � ������ �䣬���ڵ������
&& !uri.equalsIgnoreCase(context + "/" + past)
&& !checkUrl(uri, context, noFilter)) {
HttpSession httpSession = httpreq.getSession(true);
// SysConstants.USER_KEY dz users� ����
if (httpSession.getAttribute(SysConstants.USER_KEY) == null) {
httpres.sendRedirect(context + "/" +
past);// ¶ · ·��� ��� ������ ��
return;
}
}
chain.doFilter(request, response);
}
public void destroy() {
this.config = null;
}
public void init(FilterConfig filterConfig) throws ServletException {
this.config = filterConfig;