Css in the ssm framework is intercepted, and css in the ssm framework is intercepted.

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.