"1" The first example and workaround
Setting the Dispatcherservlet request mapping to/will intercept all requests. Cannot access static resources.
Workaround:
Configure the following tabs in the SPRINGMVC configuration file to resolve
<mvc:default-servlet-handler/>
Its XSD documentation is described below:
/* Configure a handler to handle static resources by forwarding requests to the servlet container's default servlet */configures a handler for serving static resource by forwarding to the Se
Rvlet container ' s default Servlet. /* Using the handler will allow the Dispatcherservlet url-pattern to be '/'; Use the servlet container's default servlet to process static resources */Uses of this handler allows using a "
/"Mapping with the Dispatcherservlet and still utilizing the Servlet container to serve static resources.
/* The handler will forward all requests to the default servlet*/this handler would forward all requests to the "Default Servlet". /* Therefore it is very important to put the order of execution of the handler in the final of all request processing ...
*/Therefore It is important, it remains last in the order of all and the other URL handlermappings. /* Use <mvc:annotation-driven/> tags or set handlermapping Instance order to ensure that the Defaultservlethttprequesthandler order is the largest. */That'll be is the case if you use the ' Annotation-driven ' element or alternatively if you is setting up your customize D handlermapping Instance is sure to set it "order" property to a value lower than that of the defaultservlethttpreques Thandler, which is inTeger. Max_value.
The explanations are as follows:
<mvc:default-servlet-handler/> will define a defaultservlethttprequesthandler in the context of SPRINGMVC to handle static resources ( The fact is to forward the request to the default servlet).
The default servlet name for the generic Web server is defaulted. If the default servlet name for the Web server you are using is not default, you need to specify it through the Default-servlet-name property.
The default servlet names under different servers correspond to the following:
Tomcat, Jetty, JBoss, and GlassFish the name of the default servlet-the name of the default servlet for the "default"
Google App Engine-"_ah_default"
resin default servlet name--"Resin-file"
WebLogic default servlet name- -"Fileservlet"
WebSphere default servlet name- -"Simplefileservlet"
"Tips:"
Using the above configuration, you will find that the normal controller jump is invalid.
The last paragraph of the XSD description is as follows:
/* Use <mvc:annotation-driven/> tags or set handlermapping Instance order to ensure that the Defaultservlethttprequesthandler order is the largest. */That'll be is the case if your use
the ' annotation-driven ' element
or alternatively if you is setting up your CU Stomized handlermapping instance are
sure to set their "order" property to a value lower than, that of the
Defaultserv Lethttprequesthandler, which is integer.max_value.
That is, either configure the <mvc:annotation-driven/> tag, or manually register the request map processing bean in XML, and set the Order property value, The order value of the bean whose implementation in the framework handles the request mapping is less than the Defaultservlethttprequesthandler's Order property value ...
The common solution is to configure <mvc:annotation-driven/> tags, details click to view request map invalidation.
Click to view controller mappings failure "2" The second example and workaround
The idea of resolving static resources is that in Springmvc.xml, the interception is set to "*.do" instead of "/".
This will not intercept requests for static resources.
It is important to note that if Shiro or other permission frames are used in the project. Then you need to pay attention to your shiro.xml configuration, examples are as follows:
<bean id= "Shirofilter" class= "Org.apache.shiro.spring.web.ShiroFilterFactoryBean" > <!--Shiro's core security interface, this The property is required--<property name= "SecurityManager" ref= "SecurityManager"/> <!--loginurl Certified submit address, if not certified
This address will be requested for authentication and this address will be requested by Formauthenticationfilter form authentication--<property name= "loginurl" value= "/login"/>
<!--Shiro Connection constraint configuration, which is the definition of the filter chain--<property name= "Filterchaindefinitions" > <value> <!--/** = anon All URLs can be accessed anonymously-<!--set Anonymous access to static resources-/images/** = a
non/js/** = anon/styles/** = Anon <!--verification code, can be accessed anonymously /validatecode = Anon <!--verification code--/dologin = Anon <!--/** = authc All URLs must be authenticated through
Before you can access-/**=authc <!--request Logout,shrio Erase sssion-->/logout=logout </value&Gt </property> </bean>
It is important to note that although the SPRINGMVC intercept is. Do, but because of the use of Shiro (or your other permission framework), you cannot directly access a static resource file other than the path that allows anonymous access in the Shiro configuration file without logging in.
For example, you put a static resource file in the project root directory, but refer to the above configuration file, obviously not in the Anonymous access path list, so you will be prompted to log in before you can access the project root static resource files. Before logging in to access the project root directory under 1.jpg, skip to the login page:
After logging in, access the project root directory under 1.jpg:
In addition, it is recommended to refer to the Shiro configuration file, such as 1.jpg placed in the images folder, then you can directly access without logging in.
The third example of "3" and the workaround
through configuration, avoid static resources being intercepted, examples are as follows:
<!--static resource access (does not intercept access to things in this directory)--
<mvc:resources location= "/js/" mapping= "/js/**"/> <mvc
: Resources location= "/css/" mapping= "/css/**"/>
<mvc:resources location= "/images/" mapping= "/images/**"/ >
<mvc:resources location= "/bootstrap/" mapping= "/bootstrap/**"/>
The XSD description document for this label is as follows:
/* Configure handler as static resources, such as Images,js and CSS files, and cache header optimizations for efficient loading in a Web browser. */
configures a handler for serving static resources such as
images, JS, and, CSS files with cache headers Optimiz Ed for efficient loading in a Web browser.
/* Allows services for any path resource that can be processed by spring */allows resources to be served out of any path that is
reachable via Spring's Resource H Andling.
The registered handler are as follows:
Org.springframework.web.servlet.resource.ResourceHttpRequestHandler
That is, the label registers Resourcehttprequesthandler to provide services for access to static resources.
The Javadoc of the handler are as follows:
{@code Httprequesthandler} that serves static resources in an optimized-according to the guidelines of Page speed, YSl ow, etc.
* <p>the {@linkplain #setLocations "locations"} property takes a list of Spring
* {@link Resource} locations fro m which static resources is allowed to
* is served by this handler. Resources could is served from a classpath location,
* e.g. "classpath:/meta-inf/public-web-resources/", allowing con Venient Packaging
* and serving of resources such as. js,. css, and others in jar files.
"4" fourth example and workaround
Specifically, this only solves the problem of directly accessing the JSP without the controller.
<mvc:view-controller/> direct access to the JSP JSP path corresponding to the VIEW-NAME is configured according to the view parser.
<!--Mvc:view-controller allows direct access to the path--
<mvc:view-controller path= "/i18n"
view-name= "i18n"/> <mvc:view-controller path= "/i18n2" view-name= "i18n2"/>