Css in the ssm framework is intercepted, and css in the ssm framework is intercepted.
Recently, I used springmvc spring mybatis framework to write a program. The request was successful and the data was obtained. The css style cannot be loaded, but the path is correct. The css file encoding is UTF-8, with Firefox debug, it is always shown that no request is received (I suspect that there is a problem with the path I wrote). Today I finally got it done. Three solutions are found, but I don't know why.
Solution 1(I personally think it is most convenient ):Web. xmlConfigure the following code:
Generally, the default Servlet name of the Web application server is "default", so here we activate Tomcat's defaultServlet to process static files.
<! -- Configure static resources -->
<Servlet-mapping>
<Servlet-name> default </servlet-name>
<Url-pattern>/js/* </url-pattern>
<Url-pattern>/css/* </url-pattern>
<Url-pattern>/images/* </url-pattern>
</Servlet-mapping>
If the default Servlet name of all your Web application servers is not "default", you must specify the default-servlet-name attribute:
<Mvc: default-servlet-handler default-servlet-name = "the default Servlet name used by the Web server"/>
Solution 2:
<! -- Springmvc-servlet.xml Controller -->
<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>
<Load-on-startup> 1 </load-on-startup> <! -- Load the configuration file as soon as it starts -->
<Async-supported> true </async-supported>
</Servlet>
<Servlet-mapping>
<Servlet-name> springmvc </servlet-name>
<Url-pattern>*. Action</Url-pattern>
</Servlet-mapping>
Note: The browser request format is as follows:
Http: // localhost: 8080/WorkOrder/login. action
Must have a. action suffix
My original statement:
<Servlet-mapping>
<Servlet-name> springmvc </servlet-name>
<Url-pattern>/</Url-pattern>
</Servlet-mapping>
When the blocking method is/, all requests are intercepted, and css files are not accessible if they are static resources.
Solution 3:
<Mvc: resources mapping = "/css/**" location = "/static/css/"/>
This method does not know why the configuration is not successful. If you know it, share it *_*
Reprinted from: http://blog.csdn.net/tonytfjing/article/details/39207551
Conclusion: When solving a problem, a good question can get twice the result with half the effort. The more you can show the essence of the problem, the more you can improve efficiency.