SpringMVC 拦截器实现
SpringMvc实现拦截器方式一:
<mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**"/> <bean class="xxx.UnLoginInteteceptor"></bean> </mvc:interceptor> </mvc:interceptors>
SpringMvc实现拦截器方式二:
<!-- 拦截器 --> <bean class="org.springframework.web.servlet.handler.MappedInterceptor"> <constructor-arg > <!-- 配置拦截请求配置 --> <array> <value>/**</value> </array> </constructor-arg> <constructor-arg> <!-- 配置拦截忽略配置 --> <array> <value>/login/**</value> </array> </constructor-arg> <constructor-arg ref="unLogininterceptor"></constructor-arg> </bean> <bean name="unLogininterceptor" class="xxx.UnLoginInteteceptor"></bean>
UnLoginInteteceptor.java文件内容
package xxx.interceptor; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.shiro.SecurityUtils; import org.apache.shiro.subject.Subject; import org.apache.shiro.web.util.WebUtils; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; public class UnLoginIntereceptor implements HandlerInterceptor { public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object obj, Exception e) throws Exception { } public void postHandle(HttpServletRequest request, HttpServletResponse response, Object obj, ModelAndView view) throws Exception { } public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception { return true; } }