springmvc请求不要后缀名,例如http://127.0.0.1:8080/plant/list 而不是http://127.0.0.1:8080/plant/list.do
解决方法
1.web.xml配置
<servlet-mapping>
<servlet-name>Spring-Servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
2.springmvc配置文件配置:
<!-- 配置 spring 拦截所有请求 -->
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
<bean class="com.interceptor.AuthInterceptor" />
</mvc:interceptors>
<!-- 配置静态不拦截的目录页面 -->
<mvc:resources mapping="/css/**" location="/css/" cache-period="8643000"/>
<mvc:resources mapping="/js/**" location="/js/" cache-period="8643000"/>
<mvc:resources mapping="/images/**" location="/images/" cache-period="8643000"/>
3.com.interceptor.AuthInterceptor拦截器中判断是静态资源就放过:
package com.manage.base.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class AuthInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
String path = request.getServletPath().toLowerCase().replace("//", "/");
if(path.startsWith("/images/")||path.startsWith("/css/")||path.startsWith("/js/")||path.startsWith("/plugins/")||path.startsWith("/upload/")){
return super.preHandle(request, response, handler);
}else{
return false;
}
}
@Override
public void afterCompletion(HttpServletRequest request,HttpServletResponse response, Object handler, Exception ex)throws Exception {
super.afterCompletion(request, response, handler, ex);
}
}