filter代码:packagecom.src.tool;importjava.io.IOException;importjavax.servlet.Filter;importjavax.servlet.FilterChain;importjavax.servlet.FilterConfig;importjavax.servlet....
filter代码:
package com.src.tool;
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 javax.servlet.http.HttpSession;
import com.src.model.User;
public class LoginFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain fc) throws IOException, ServletException {
HttpServletRequest servletRequest = (HttpServletRequest) request;
HttpServletResponse servletResponse = (HttpServletResponse) response;
HttpSession session = servletRequest.getSession();
User user = (User)session.getAttribute("CURRENT_USER");
if(user == null){
servletResponse.sendRedirect("/TravelAgencyXSystem/login.jsp");
}
}
public void init(FilterConfig arg0) throws ServletException {
}
}
xml配置文件:
login
com.src.tool.LoginFilter
login
/*
错误页面
对不起 没财富了
展开