<filter>
<filter-name>SessionFilter</filter-name>
<filter-class>
com.huawei.it.tcps.filter.SessionFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>SessionFilter</filter-name>
<url-pattern>/system/*</url-pattern>
</filter-mapping>
public void doFilter(ServletRequest request, ServletResponse response, FilterChain china) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setContentType("text/xml; charset=GBK");
httpResponse.setHeader("Pragma","No-cache");
httpResponse.setHeader("Cache-Control","no-cache");
httpResponse.setDateHeader("Expires", 0);
HttpSession session = httpRequest.getSession();
String userId = (String)session.getAttribute(Constants.USERSESSIONID);
boolean isLogin = true;
if(null==userId){
String redpath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+httpRequest.getContextPath()+"/ldapAction.do?method=ldapLogin";
//String redpath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+httpRequest.getContextPath()+"/innerLogin.do?method=login";
httpResponse.sendRedirect(redpath);
isLogin = false;
}
if(isLogin){
china.doFilter(request,response);
}
}
<filter-name>SessionFilter</filter-name>
<filter-class>
com.huawei.it.tcps.filter.SessionFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>SessionFilter</filter-name>
<url-pattern>/system/*</url-pattern>
</filter-mapping>
public void doFilter(ServletRequest request, ServletResponse response, FilterChain china) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setContentType("text/xml; charset=GBK");
httpResponse.setHeader("Pragma","No-cache");
httpResponse.setHeader("Cache-Control","no-cache");
httpResponse.setDateHeader("Expires", 0);
HttpSession session = httpRequest.getSession();
String userId = (String)session.getAttribute(Constants.USERSESSIONID);
boolean isLogin = true;
if(null==userId){
String redpath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+httpRequest.getContextPath()+"/ldapAction.do?method=ldapLogin";
//String redpath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+httpRequest.getContextPath()+"/innerLogin.do?method=login";
httpResponse.sendRedirect(redpath);
isLogin = false;
}
if(isLogin){
china.doFilter(request,response);
}
}