且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

资源被解释为样式表,但在控制台中以MIME类型text/html错误进行传输

更新时间:2022-04-10 21:35:02

我遇到了同样的问题.好吧,我只是试图使用servlet加载欢迎的jsp页面,该页面的标头中包含一个.css文件.

I've faced the same issue. Well, I was just trying to use a servlet to load welcome jsp page, which contains a .css file in header.

<head>
   <link rel="stylesheet" type="text/css" href="css/base.css">
</head>

我遇到了同样的错误资源被解释为样式表,但以MIME类型text/html传输:" http://localhost:8080/webapp/css/style.css "

And I got the same error "Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8080/webapp/css/style.css"

当我在chrome中使用开发人员工具时,在网络"标签下,点击我的Web应用的登录网址" http://localhost:8080/webapp/"

When I used developer tools in chrome, under 'Network' tab, two calls were made when hit my webapp's landing url "http://localhost:8080/webapp/"

我在web.xml中将默认的servlet网址从"/"更改为"/index"

I changed my default servlet url from "/" to "/index" in web.xml

<servlet-mapping>
    <servlet-name>NextServlet</servlet-name>
    <url-pattern>/index</url-pattern>
</servlet-mapping>

然后将"./"添加到href,

And then added "./" to href,

 <head>
   <link rel="stylesheet" type="text/css" href="./css/base.css">
</head>

有效.