2016-12-22 41 views
0

學習JSP並遇到未加載css/js內容的問題。我有一個jsp頁面,在那裏我有引導CSS和JS使用標準的HTML鏈接和腳本標籤引用:JSP Tomcat7靜態css和js文件未加載

<link rel="stylesheet" type="text/css" link="/bootstrap/css/bootstrap.css" /> 

<script src="/WebIntro/bootstrap/js/bootstrap.js"></script> 

既不是他們的工作和Chrome是給我的下面控制檯:

Resource interpreted as Stylesheet but transferred with MIME type text/plain: 

如果我使用include指令,它的工作原理爲CSS,但拉的所有內容到文件:

<%@include file="/bootstrap/css/bootstrap.css"%> 

的JSP具有以下@page和meta標籤:

<%@page contentType="text/html" %> 

<meta http-equiv = "Content-Language" content = "en"/> 
<meta http-equiv = "Content-Type" content="text/html; charset=utf-8"> 

我試着用搜索引擎,發現在web.xml中的mime-mapping元素,但以下似乎沒有影響:

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

<mime-mapping> 
    <extension>js</extension> 
    <mime-type>application/javascript</mime-type> 
</mime-mapping> 

如果有一些標準的Tomcat配置需要發生我是不知道,因爲我是Tomcat的新手;使用Tomcat 7和eclipse,這是一個Maven項目。

+0

http://stackoverflow.com/questions/22631158/resource-interpreted-as-stylesheet-but-transferred-with-mime-type-text-html-see –

回答

0

對我來說這個解決方案非常奇怪。自從我在eclipse/maven中構建項目以來,對web.xml文件所做的更改未反映在tomcat webapp應用程序目錄中的web.xml中。除了web.xml之外,包中的其他所有內容都可以更新(據我所知)?

因此,我發現目標>> project-SNAPSHOT >> WEB-INF >> web.xml(這應該是派生的)內的eclipse中的web.xml文件。在那裏強行改變,它的工作,改變被拿起,我的原始問題消失了。

我猜我曾經無意中破壞了某種類型的依賴鏈接或某種方式,但是一旦我添加了servlet,映射等後,一切工作正常。

奇怪。