首页 > 学院 > 开发设计 > 正文

SpringMVC拦截器筛选

2019-11-14 15:30:18
字体:
来源:转载
供稿:网友

如果只配置拦截类似于*.do格式的url,则对静态资源的访问是没有问题的,但是如果配置拦截了所有的请求(如我们上面配置的“/”),就会造成js文件、CSS文件、图片文件等静态资源无法访问

一般Web应用服务器默认的Servlet名称是"default",所以这里我们激活Tomcat的defaultServlet来处理静态文件

 

 Tomcat, Jetty, JBoss, and GlassFish  默认 Servlet的名字 -- "default"         Resin 默认 Servlet的名字 -- "resin-file"         WebLogic 默认 Servlet的名字  -- "FileServlet"         WebSphere  默认 Servlet的名字 -- "SimpleFileServlet"                 如果你所有的Web应用服务器的默认Servlet名称不是"default",则需要通过default-servlet-name属性显示指定

 

java代码 复制代码 收藏代码
  1. <filter>  
  2.         <filter-name>struts2</filter-name>  
  3.         <!-- org.apache.struts2.dispatcher.FilterDispatcher -->  
  4.         <!-- org.apache.struts2.dispatcher.ng.filter.StrutsPRepareAndExecuteFilter -->  
  5.         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  
  6.     </filter>  
  7.     <filter-mapping>  
  8.         <filter-name>struts2</filter-name>  
  9.         <url-pattern>*.action</url-pattern>  
  10.     </filter-mapping>  
  11.       
  12.     <servlet-mapping>    
  13.     <servlet-name>default</servlet-name>  
  14.     <url-pattern>*.action</url-pattern>    
  15.      <url-pattern>/js/*</url-pattern>    
  16.     <url-pattern>/css/*</url-pattern>    
  17.     <url-pattern>/images/*</url-pattern>  
  18.     <url-pattern>/image/*</url-pattern><!--    
  19.     <url-pattern>/article/*</url-pattern>     
  20.     --></servlet-mapping>  
  21.     
  22. <!-- springmvc配置 -->   
  23.     <servlet>  
  24.         <servlet-name>springmvc</servlet-name>  
  25.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  26.         <init-param>  
  27.             <param-name>contextConfigLocation</param-name>  
  28.             <param-value>classpath:springmvc-servlet.xml</param-value>  
  29.         </init-param>  
  30.         <load-on-startup>2</load-on-startup>  
  31.     </servlet>  
  32.     <servlet-mapping>  
  33.         <servlet-name>springmvc</servlet-name>  
  34.         <url-pattern>/selfhelp/*</url-pattern>  
  35.     </servlet-mapping>  
<filter>		<filter-name>struts2</filter-name>		<!-- org.apache.struts2.dispatcher.FilterDispatcher -->		<!-- org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter -->		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>	</filter>	<filter-mapping>		<filter-name>struts2</filter-name>		<url-pattern>*.action</url-pattern>	</filter-mapping>        <servlet-mapping>      <servlet-name>default</servlet-name>    <url-pattern>*.action</url-pattern>       <url-pattern>/js/*</url-pattern>      <url-pattern>/css/*</url-pattern>      <url-pattern>/images/*</url-pattern>    <url-pattern>/image/*</url-pattern><!--      <url-pattern>/article/*</url-pattern>       --></servlet-mapping>  <!-- springmvc配置 --> 	<servlet>		<servlet-name>springmvc</servlet-name>		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>		<init-param>			<param-name>contextConfigLocation</param-name>			<param-value>classpath:springmvc-servlet.xml</param-value>		</init-param>		<load-on-startup>2</load-on-startup>	</servlet>	<servlet-mapping>		<servlet-name>springmvc</servlet-name>		<url-pattern>/selfhelp/*</url-pattern>	</servlet-mapping>

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表