Java Web: Send request, CSS file and JS file reference failed

Problem Description

After the browser enters the path and press Enter, the page is displayed, but the CSS beautification result is not displayed normally.
Press F12 to debug on the browser side and found that the Console reported a yellow warning: Resource interpreted as Stylesheet but transferred with MIME type text/html and a red error: Uncaught ReferenceError: $ is not defined .

  • Yellow warning means: CSS file request came, but it was translated into HTML file;
  • Red error means: Jquery is not loaded successfully (other package functions are not used in JSP, such as EL, JSTL);

problem causes

Searching on the Internet found two reasons:

  1. Due to the setting: response.setContentType("text/html;charset=utf-8");
  2. Due to the setting of a global filter (Filter is set to: /*);

Solution

  1. Caused by reason 1, it can be judged that the request is CSS, then set response.setContentType("text/css;charset=utf-8");'''

  2. Reason 2: Filter sets the CSS file request filter:
<filter-mapping>
        <filter-name>FilterCss</filter-name>
        <url-pattern>*.css</url-pattern>
</filter-mapping>

The effect will be known after a trial.

Guess you like

Origin blog.51cto.com/weiyuqingcheng/2597539