今天其实是很烦躁的一天。浑身乏力,好蛋疼,很多事,都感觉很压抑,效率很低。
过滤器:
web.xml配置:对应java类:package com.oauth.system.utils;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.HttpServletResponseWrapper;import com.oauth.mobile.bean.UserMb;public class MobileFilter implements Filter { public FilterConfig config; @Override public void destroy() { this.config = null; } /* (non-Javadoc) * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) * 过滤手机店的 */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest hrequest = (HttpServletRequest)request; HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper((HttpServletResponse) response); String logonStrings = config.getInitParameter("logonStrings"); // String redirectPath = hrequest.getContextPath() + config.getInitParameter("redirectPath");// String openid = request.getParameter("openid"); String[] logonList = logonStrings.split(";"); if (MobileFilter.isContains(hrequest.getRequestURI(), logonList)) { // chain.doFilter(request, response); return; } UserMb user = ( UserMb ) hrequest.getSession().getAttribute("mobileUser");// if (user == null) { wrapper.sendRedirect(redirectPath); return; }else { chain.doFilter(request, response); return; } } @Override public void init(FilterConfig config) throws ServletException { this.config = config; } public static boolean isContains(String container, String[] regx) { boolean result = false; for (int i = 0; i < regx.length; i++) { if (container.indexOf(regx[i]) != -1) { return true; } } return result; }} mobileFilter com.oauth.system.utils.MobileFilter logonStrings /mobileUser/forgetPassword;/mobileUser/init;/mobileUser/initLogin;/mobileUser/login;/mobileUser/initRegedit;/mobileUser/validateAccountCode;/mobileUser/validateBindPhone;/mobileUser/register;/mobileUser/sendVerifyCode;/mobileUser/verifyCode; redirectPath /mobileUser/initLogin