访问静态文件

springMVC访问静态文件,图片,js,css等

方法一:在springMVC-servlet.xml配置,用mvc:resources方法

<mvc:resources location="/img/" mapping="/img/**" />
<mvc:resources location="/js/" mapping="/js/**" />
<mvc:resources location="/js/" mapping="/js/**" />


方法二:在web.xml配置 激活Tomcat的defaultServlet来处理静态文件

<servlet-mapping>
	<servlet-name>spring</servlet-name>
	<url-pattern>/</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>/upload/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
     <servlet-name>default</servlet-name>
     <url-pattern>*.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
     <servlet-name>default</servlet-name>
     <url-pattern>/img/*</url-pattern>
</servlet-mapping>


你可能感兴趣的