JSP file cannot load CSS, JS problem

Source: Internet
Author: User

Today encountered a problem is, in the JSP introduced CSS, JS, the state of the request is 200, but the CSS, JS content is empty.

This is because the servlet has a url-pattern, the CSS, JS path as a servlet processing

The Url-pattern has 5 configuration modes:

(1)/xxx: Exactly match the path of the/xxx
(2)/xxx/*: matches the path beginning with/xxx, the request must contain XXX.
(3)/*: Match/down all paths, request can enter action or controller, but forward JSP is intercepted again, cannot access JSP interface.
(4). XX: Matches the path ending with XX, all requests must end with. XX, but will not affect access to static files.
(5)/: Default mode, paths that are not matched will be mapped to the sting servlet, and static files such as Jpg,js,css will also be intercepted and inaccessible.

Workaround, add the following configuration to Web. xml:

<!--static Resources--      <servlet-mapping>          <servlet-name>default</servlet-name>          <url-pattern>*.css</url-pattern>      </servlet-mapping>        <servlet-mapping>          <servlet-name>default</servlet-name>          <url-pattern>*.gif</url-pattern>        </servlet-mapping>        <servlet-mapping>          <servlet-name>default</servlet-name>          <url-pattern>*.jpg</url-pattern>      </servlet-mapping>        <servlet-mapping>          <servlet-name>default</servlet-name>          <url-pattern>*.js</url-pattern>      </servlet-mapping>  

  

JSP file cannot load CSS, JS problem

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.