“资源解释为样式表,但使用MIME类型text / html传输”问题java web项目

时间:2014-12-28 15:44:27

标签: java css java-ee include mime

我的动态网络项目存在问题。 树枝是

的WebContent
|
|
引导
CSS
JS
WEB-INF
|
|
connection.jsp

然后在connection.jsp中我做了这个:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap-theme.css"/>
<link rel="stylesheet" type="text/css" href="css/connection.css"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/register.js">     </script>
<title>Jweb</title>
</head>
<body>

所有的css都不适用,而在chrome的控制台上我有这个:

Resource interpreted as Stylesheet but transferred with MIME type text/html: 
"http://localhost:8080/jweb/bootstrap/css/bootstrap-theme.css". localhost/:10
Resource interpreted as Stylesheet but transferred with MIME type text/html:          "http://localhost:8080/jweb/bootstrap/css/bootstrap.css". localhost/:9
Resource interpreted as Stylesheet but transferred with MIME type text/html:    "http://localhost:8080/jweb/css/footer.css". localhost/:11
Resource interpreted as Stylesheet but transferred with MIME type text/html:  "http://localhost:8080/jweb/css/header.css". localhost/:12
Resource interpreted as Script but transferred with MIME type text/html:     "http://localhost:8080/jweb/js/jquery.js". localhost/:14
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:8080/jweb/js/bootstrap.js". localhost/:15
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8080/jweb/css/connection.css". 

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<jsp-config>
<jsp-property-group>
 <url-pattern>*.jsp</url-pattern>
 <include-prelude>/WEB-INF/taglibs.jsp</include-prelude>
</jsp-property-group>
</jsp-config>
</web-app>

我试着在2天前解决这个问题而且我还在上面。 你能帮我解决一下吗?

2 个答案:

答案 0 :(得分:0)

快速&#34; mime映射web.xml&#34;搜索建议您在mime-mapping中使用web.xml元素:

<mime-mapping>
    <extension>css</extension>
    <mime-type>text/css</mime-type>
</mime-mapping>

E.g。 (在结束</web-app>行之前的新行):

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<jsp-config>
<jsp-property-group>
 <url-pattern>*.jsp</url-pattern>
 <include-prelude>/WEB-INF/taglibs.jsp</include-prelude>
</jsp-property-group>
</jsp-config>
<mime-mapping>
    <extension>css</extension>
    <mime-type>text/css</mime-type>
</mime-mapping>
</web-app>

答案 1 :(得分:0)

以下是您尝试使用的示例web.xml。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">

                <servlet>
                    <servlet-name>welcome</servlet-name>
                    <jsp-file>index.jsp</jsp-file>
                    <load-on-startup>1</load-on-startup>
                </servlet>

                <servlet-mapping>
                    <servlet-name>welcome</servlet-name>
                    <url-pattern>/*</url-pattern>
                </servlet-mapping>

                <jsp-config>
                    <jsp-property-group>
                        <url-pattern>*.jsp</url-pattern>
                        <include-prelude>/WEB-INF/taglibs.jsp</include-prelude>
                    </jsp-property-group>
                </jsp-config>

</web-app>