代码
package com.ucit.filter;
import java.io.IOException;
import java.util.ArrayList;
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 javax.servlet.http.HttpSession;
import com.ucit.struts.action.LoginAction;
public class TuserCheckFilter implements Filter {
public void destroy() {
// TODO Auto-generated method stub
}
static ArrayList<HttpSession> tusers = LoginAction.tusers;
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
// 当前SESSION不在Tusers里的时候,就让他跳到登陆页面
HttpSession nowSession = ((HttpServletRequest) arg0).getSession();
boolean in = false;
for (int i = 0; i < tusers.size(); i++) {
if (nowSession == tusers.get(i)) {
in = true;
break;
}
}
if (!in) {
if (!((HttpServletRequest) arg0).getServletPath().equals(
"/login.jsp"))
{
((HttpServletResponse) arg1)
.sendRedirect("/oracleManagement/login.jsp");
} else {
arg2.doFilter(arg0, arg1);
}
;
} else {
arg2.doFilter(arg0, arg1);
}
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}
import java.io.IOException;
import java.util.ArrayList;
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 javax.servlet.http.HttpSession;
import com.ucit.struts.action.LoginAction;
public class TuserCheckFilter implements Filter {
public void destroy() {
// TODO Auto-generated method stub
}
static ArrayList<HttpSession> tusers = LoginAction.tusers;
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
// 当前SESSION不在Tusers里的时候,就让他跳到登陆页面
HttpSession nowSession = ((HttpServletRequest) arg0).getSession();
boolean in = false;
for (int i = 0; i < tusers.size(); i++) {
if (nowSession == tusers.get(i)) {
in = true;
break;
}
}
if (!in) {
if (!((HttpServletRequest) arg0).getServletPath().equals(
"/login.jsp"))
{
((HttpServletResponse) arg1)
.sendRedirect("/oracleManagement/login.jsp");
} else {
arg2.doFilter(arg0, arg1);
}
;
} else {
arg2.doFilter(arg0, arg1);
}
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}