要学的
在你项目中的web.xml中加入filter,如下:
com.dc.portal.system.sessionmgr.SessionFilter
filter-class的值是你自己创建的类,给你个大致的例子:
public class SessionFilter implements Filter{
public void destroy() {
}
//这个doFilter方法必须有
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpreq = (HttpServletRequest) request;
HttpServletResponse httpres = (HttpServletResponse) response;
if(httpreq.getSession().getAttribute("userInfo") == null){
((HttpServletResponse)response).sendRedirect("你要重定向的地址");
}else{
chain.doFilter(httpreq, httpres);
}
}
}