Record SpringMVC question whether static resources encountered in the WEB-INF

  • If the static resources (jsp, css, img, js ) all on the web path , jsp linked to various css, js, img and other resources to be configured in the spring or in the configuration file web.xml:
<mvc:resources location="/js/" mapping="/js/**"></mvc:resources>
<mvc:resources location="/css/" mapping="/css/**"></mvc:resources>
<mvc:resources location="/img/" mapping="/img/**"></mvc:resources>

or it could be:

<servlet-mapping>
	<servlet-name>default</servlet-name>
    <url-pattern>/css/*</url-pattern>
    <url-pattern>/js/*</url-pattern>
    <url-pattern>/img/*</url-pattern>
</servlet-mapping>
  • If the static resources (jsp, css, img, js ) entirely on the WEB-INF path , you need to configure a static resource is:
<mvc:resources mapping="/imgfile/**" location="/WEB-INF/imgfile/"></mvc:resources>
<mvc:resources mapping="/jsfile/**" location="/WEB-INF/jsfile/"></mvc:resources>

Not found in web.xml suitable configuration allows entry into force of static resources, resources under WEB-INF path is safe, with direct access url is not acquired, the page does not jump directly effected through hyperlinks directly initiator 404, by the need to jump through the Controller view resolver;

Set interceptor:

  • For resource path in the web can not be performed with the springmvc <mvc:interceptors>interception performed, if doFilter to intercept a filter filtration method may be used to achieve Filter, rewritable
  • For resources in the WEB-INF path can intercept, for example:
<mvc:interceptors>
	<mvc:interceptor>
		<!--拦截的具体方法-->
		<mvc:mapping path="/*"/>
		
		<!--不拦截的具体方法-->
		<mvc:exclude-mapping path="/getData"/>
		
		<bean class="cn.hp.util.MyInterceptor"></bean>
	</mvc:interceptor>
</mvc:interceptors>

But not yet to find resources to intercept only jsp page path wording, if css, js, img and other resources are configured <mvc:resources>will not be intercepted; /*is to intercept all requests;

Published 12 original articles · won praise 3 · Views 237

Guess you like

Origin blog.csdn.net/qq_38599840/article/details/105128861