In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces what the role of tags in Spring MVC is, the content is very detailed, interested friends can refer to, hope to be helpful to you.
< mvc:resources />The role of
In the Spring MVC framework, request processing for static resources can be configured in addition to
< mvc:default-servlet-handler />Tags, in addition to being handled by containers, can also be used
< mvc:resources />Tags are handled at the framework level.
As you can see from the XML Schema file description of Spring MVC, through
< mvc:resources />Tag configuration enables the Spring MVC framework to configure a Handler to handle static resources, such as images, JS,CSS and other files, and by configuring Cache-related Headers to enable browsers to load more efficiently. At the same time, this configuration allows static resources to be placed under any path that can be read by the Spring MVC framework.
< mvc:resources />Configuration of
< mvc:resources />There are mainly the following configurations:
Mapping (required, type: string) is based on the URL matching rules of the current Servlet context, such as "/ resources/**".
Location (required, type: string) the placement path of static resources, which meets the matching rules of Spring resources. You can use "classpath:". When there are multiple paths, use "," to splice, for example: "/, classpath:/META-INF/public-web-resources/".
Cache-period (optional, type: string) is used to configure the cache time of the Handler class for static resources, in seconds. By default, no cached Header is sent, relying only on the modification timestamp of the last-modified parameter. When set to 0, resource caching is disabled; when a positive integer is set, it indicates the longest valid time of the resource cache.
Order (optional, type: int) is used to configure the order in which the Handler class processes requests, default to the lowest priority value of-1.
The role of the ResourceHttpRequestHandler class
In the ResourceHttpRequestHandler class, get static resources from the server or jar package by parsing the parameters corresponding to location in the tag.
At the same time, you can configure parser classes such as VersionResourceResolver class, GzipResourceResolver class, and CachingResourceResolver class or converter classes such as CssLinkResourceTransformer class and AppCacheManifestTransformer class to provide custom processes such as adding version numbers and Gzip compression for static resources. By default, only the PathResourceResolver class is used to query static resources based on URL.
When processing Request requests, the ResourceHttpRequestHandler class defaults to calculate the Last-Modified parameters in the Headers request header to determine whether to return the request code 304and inform the browser to use cached data to improve the efficiency of request response.
< mvc:resources />Vs.
< mvc:default-servlet-handler />Similarities and differences
Because all the requests handled by the framework in Spring MVC are handled by the DispatcherServlet class, it is impossible to handle the static resource requests in a friendly and compatible manner. At this point, the framework provides two processing strategies for processing:
Pass through
< mvc:default-servlet-handler />Tag to transfer the request processing to the WEB container for efficient processing. It can better rely on the request processing capacity of the container itself, and undertake the processing of static resource requests.
Pass through
< mvc:resources />Tag to configure the corresponding Resolver class and Transformer class to handle static resource requests at the framework level in order to decouple the container. And through the integration of request response optimization processing logic to meet the needs of business and performance.
About what the role of tags in Spring MVC is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.