登录过滤器


/**
 * 
 * @author li_yf 登录过滤
 * 
 */
public class LoginFilter implements Filter {
	public void destroy() {
	}

	/**
	 * 过滤方法
	 */
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = ((HttpServletRequest) request);
		req.setCharacterEncoding("utf-8");
		((HttpServletResponse) response).setCharacterEncoding("utf-8");
		String url = req.getRequestURI();
		System.out.println("url=" + url);
		String param = req.getParameter("o");
		if (req.getSession().getAttribute("USER") != null
				|| url.equals("/lwcard/login.jsp")
				|| (url.equals("/lwcard/user.do") && param != null && !param
						.equals(""))) {
			chain.doFilter(request, response);
		} else {
			((HttpServletResponse) response).sendRedirect("login.jsp");
		}
	}

	public void init(FilterConfig config) throws ServletException {
	}
}



<filter>
  <filter-name>LoginFilter</filter-name>
  <filter-class>com.business.card.conmon.util.LoginFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>LoginFilter</filter-name>
  <url-pattern>*.jsp</url-pattern>
 </filter-mapping>
 <filter-mapping>
  <filter-name>LoginFilter</filter-name>
  <url-pattern>*.do</url-pattern>
 </filter-mapping>

你可能感兴趣的:(jsp,xml)