public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
// TODO Auto-generated method stub
//log.info("==============执行顺序: 1、preHandle================");
String url=request.getRequestURL().toString();
url = url.substring(url.lastIndexOf("/") + 1);
if(request.getSession().getAttribute("user") != null){
return true;
}else{
if(mappingURL==null || !url.matches(mappingURL)){
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
pw.print("<script>window.parent.location.href='"+request.getContextPath() + "/login.jsp'"+";</script>");
return false;
}
return true;
}
}
<!-- 拦截器 -->
<mvc:interceptors>
<!-- 多个拦截器,顺序执行 -->
<mvc:interceptor>
<mvc:mapping path="/**" /><!-- 如果不配置或/*,将拦截所有的Controller -->
<bean class="com.hw.ydcg.web.utils.CommonInterceptor">
<property name="mappingURL" value="login.htm"/>
</bean>
</mvc:interceptor>
</mvc:interceptors>
问题是:目前的配置是拦截所有的请求,如果不是login.htm则返回login.jsp。现在我想要的是 也拦截所有的请求,但是针对特定的方法或jsp可以通过(例如:*****/index.jsp, *****/aaa.htm),怎么实现.
------解决思路----------------------