我有这个问题。Chrome继续返回此错误

资源解释为样式表,但以MIME类型text/html传输

受此错误影响的文件只有Style、chosen和jquery-gentleselect(以相同方式导入索引的其他CSS文件工作良好且没有错误)。我已经检查了我的MIME类型和文本/css已经在css上。

老实说,我想从理解问题开始(这似乎是我一个人做不到的事情)。


当前回答

In my case, same error was coming with JSP. This is how I got to the root of this issue: I went to the Network tab and clearly saw that the browser request to fetch the css was returning response header having "Content-type" : "text/html". I opened another tab and manually hit the request to fetch the css. It ended up returning a html log in form. Turns out that my web application had a url mapping for path = / Tomcat servlet entry : (@WebServlet({ "/, /index", }). So, any unmatching request URLs were somehow being matched to / and the corresponding servlet was returning a Log in html form. I fixed it by removing the mapping to /

此外,tomcat配置wrt处理css MIME-TYPE已经存在。

其他回答

我有同样的问题,几分钟后,我破译,我错过了添加文件扩展名到我的头。所以我改了下面这行:

<link uic-remove rel="stylesheet" href="css/bahblahblah">

to

<link uic-remove rel="stylesheet" href="css/bahblahblah.css"> 

我也遇到过类似的问题。在这个奇妙的Stack Overflow页面中探索解决方案。

user54861的响应(大小写不匹配的名字)让我很好奇,再次检查我的代码,并意识到“我没有上传两个js文件,我在头标签中加载了它们”。: -)

当我上传他们的问题跑了!并且代码运行和页面呈现没有任何其他错误!

所以,这个故事的寓意是,不要忘记确保你所有的js文件都上传到了页面需要它们的地方。

我也遇到了同样的问题,用同样的。htaccess文件来创建漂亮的url。经过几个小时的观察和实验。我发现这个错误是因为相对链接的文件。

浏览器将开始为所有css, js和图像文件获取相同的源HTML文件,当我将浏览几个步骤深入到服务器。

为了解决这个问题,你可以在HTML源代码上使用<base>标签,

<base href="http://localhost/assets/">

链接到这样的文件,

<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="js/script.js"></script>

或者对所有文件使用绝对链接。

<link rel="stylesheet" type="text/css" href="http://localhost/assets/css/style.css" />
<script src="http://localhost/assets/js/script.js"></script>
<img src="http://localhost/assets/images/logo.png" />

如果您使用的是JSP,则此问题可能来自您的servlet映射。 如果你的映射默认使用url,就像这样:

@WebServlet("/")

然后容器解释CSS url,并转到servlet,而不是转到CSS文件。

我有同样的问题,我改变了我的映射,现在一切正常

试试这个<link rel="stylesheet" type="text/css" href="../##/yourcss.css">

哪里##是你的文件夹,其中是你的。css -文件

别忘了:..(双点)。