1. 程式人生 > >springmvc的前端控制器對css、js等進行過濾

springmvc的前端控制器對css、js等進行過濾

web.xml配置如下:

	<!-- 配置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>
	</servlet>
	<servlet-mapping>
		<servlet-name>springmvc</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>

此時,springmvc會對css、js等進行過濾攔截,會導致加在不了,此時再忽略對資原始檔的攔截,才能正常執行:

	<servlet-mapping>     
            <servlet-name>default</servlet-name>    
    	<url-pattern>*.jpg</url-pattern>       
	</servlet-mapping>      
	<servlet-mapping>         
	   <servlet-name>default</servlet-name>      
	   <url-pattern>*.js</url-pattern>      
	</servlet-mapping>      
	<servlet-mapping>          
	   <servlet-name>default</servlet-name>         
	   <url-pattern>*.css</url-pattern>        
	</servlet-mapping>
	<servlet-mapping>          
	   <servlet-name>default</servlet-name>         
	   <url-pattern>*.png</url-pattern>        
	</servlet-mapping> 

ok!