I want to determine whether he has rights to access the url or not.But I want to give all the css,js can be accessed.So I config the web.xml like this:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet- class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="com.test.web.interceptor.MyInterceptor">
<property name="loginUrl">
<value>http:
</property>
</bean>
</mvc:interceptor>
</mvc:interceptors>
and set spring-servlet.xml like this:
<mvc:resources location="/css/" mapping="/css/**" />
<mvc:resources location="/js/" mapping="/js/**" />
and MyInterceptor like this:
public class MyInterceptor implements HandlerInterceptor {
@Override
public void afterCompletion(HttpServletRequest arg0,
HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
}
@Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
Object arg2, ModelAndView arg3) throws Exception {
}
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
response.setCharacterEncoding("UTF-8");
StringBuffer currentUrl = request.getRequestURL();
String path = request.getServletPath();
if(path.matches( "(.*/((css)|(js)|(images)).*)"
)){
System.out.println(path);
return true;
}
}
After this,I think that the css and js request can be accessed and not go to my interceptors.BUt it is wrong.Now I have two questions:
I have set the mvc:resources,the book say that it will not be processed by DispatcherServlet,Why do the css or js url request still go to MyInterceptor?
I visit the index.jsp page,in MyInterceptor I can get the css request,js request,but Why do I not get the jsp page request?
What I have tried:
I have search the intenet and try to code two hours.