<mvc:resources mapping="/resources/**" location="/static/resources" /> <mvc:resources mapping="/static/css/**" location="/static/css/" /> <mvc:resources mapping="/static/images/**" location="/static/images/" /> <mvc:resources mapping="/static/js/**" location="/static/js/" />
<mvc:interceptors>
<!-- 使用bean定义一个Interceptor,直接定义在mvc:interceptors根下面的Interceptor将拦截所有的请求
<bean class="com.myTree.interceptor.LoginInterceptor" />-->
<mvc:interceptor>
<mvc:mapping path="/**" />
<!-- 需排除拦截的地址 -->
<mvc:exclude-mapping path="/Login"/>
<mvc:exclude-mapping path="/login"/>
<mvc:exclude-mapping path="/sattic/**"/>
<!-- 定义在mvc:interceptor下面的表示是对特定的请求才进行拦截的 -->
<beans:bean class="com.myTree.interceptor.LoginInterceptor" >
</beans:bean>
</mvc:interceptor>
</mvc:interceptors>
<mvc:mapping path="/**" />
<!-- 拦截器配置 -->
<mvc:interceptors>
<!-- session超时 -->
<mvc:interceptor>
<mvc:mapping path="/*/*"/>
<bean class="com.myTree.interceptor.LoginInterceptor">
<property name="allowUrls">
<list>
<!-- 如果请求中包含以下路径,则不进行拦截 -->
<value>/login</value>
<value>/js</value>
<value>/css</value>
<value>/image</value>
<value>/images</value>
</list>
</property>
</bean>
</mvc:interceptor>
</mvc:interceptors>
/**
* 处理登录拦截器
*/
public class LoginInterceptor implements HandlerInterceptor{
public String[] allowUrls;//还没发现可以直接配置不拦截的资源,所以在代码里面来排除
public void setAllowUrls(String[] allowUrls) {
this.allowUrls = allowUrls;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {<pre name="code" class="java"> <span style="white-space:pre"> </span>String requestUrl = request.getRequestURI().replace(request.getContextPath(), "");
System.out.println(requestUrl);
if(null != allowUrls && allowUrls.length>=1){
for(String url : allowUrls) {
if(requestUrl.contains(url)) {
return true;
}
}
}
<!--该servlet为tomcat,jetty等容器提供,将静态资源映射从/改为/static/目录,如原来访问http://localhost/foo.css,现在http://localhost/static/foo.css --> <!-- 不拦截静态文件 --> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/js/*</url-pattern> <url-pattern>/css/*</url-pattern> <url-pattern>/images/*</url-pattern> <url-pattern>/fonts/*</url-pattern> </servlet-mapping>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有