試圖確定在部署到Tomcat 6的web應用程序 中放置樣式表的位置/方式,以便可以解析styles.css。 我已經嘗試了所有我能想到但沒有成功的事情。爲什麼Tomcat 6找不到我的styles.css
我做了這些測試揪出來的是把文件,但 一點成功。
1.) put css in-line with style attribute to verify text display green.
<div id="xxx" style="color:green;"> This worked.
Then I removed the attribute and
2.) moved it into a in-file <style></style> stmt in the jsp. This also worked.
I copied the css stmt into styles.css and disabled the in-line stmt in the jsp.
3.) added <link></link> stmts to file. I tried several path refs to the file.
And I put the file in several different directory locations to see where
it would get resolved. (none were found)
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<link rel="stylesheet" type="text/css" href="/css/styles.css">
Using FireBug (css tab) I see the follow information for these links
* <link rel="stylesheet" type="text/css" href="styles.css">
this displays the src to index.html in the root dir
* <link rel="stylesheet" type="text/css" href="css/styles.css">
this displays the msg
Apache Tomcat/6.0.13 - Error report
HTTP Status 404
The requested resource() is not available.
* <link rel="stylesheet" type="text/css" href="/css/styles.css">
this displays
Failed to load source for: http://192.168.5.24:9191/css/clStyles.css
contextPath中的/微博 和基本路徑是http://192.168.5.24:9191/microblog
這裏是我使用的測試代碼。
我使用Spring 3.我有一個簡單的JSP
- test.jsp的 -
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<link rel="stylesheet" type="text/css" href="/css/styles.css">
<style>
#Yxxx {color:green;}
</style>
</head>
<body>
<div id="xxx">
<h2>Test <%=path%> <%=basePath%></h2>
</div>
</body>
</html>
我放在styles.css的文件在許多目錄位置看到 哪裏它可能會得到解決,但似乎沒有發現。
在Tomcat中6的部署展開的Web應用程序的目錄結構
webapps/microblog
webapps/microblog/styles.css
webapps/microblog/index.html
webapps/microblog/css/styles.css
webapps/microblog/WEB-INF/css/styles.css
webapps/microblog/WEB-INF/jsp/admintest/styles.css
webapps/microblog/WEB-INF/jsp/admintest/test.jsp
那麼如何讓Tomcat的6解決.css文件?
謝謝你們兩位。這個信息很有幫助。 根據您的建議更改以及對我的(將格式從/更改爲 * .html)進行的更改,此操作正常。 我想了解爲什麼url-pattern更改啓用 Tomcat來解決refs。任何一個人都可以指向 文章或提供解釋。 在此先感謝。 –
user976831
如果你在'/'上映射一個servlet,那麼你基本上覆蓋了servletcontainer自己的默認servlet,它用於所有與所有其他聲明servlet的URL模式不匹配的請求(例如,靜態資源如圖像,CSS,JS ,等文件)。如果是Tomcat,請查看http://tomcat.apache.org/tomcat-7.0-doc/default-servlet.html – BalusC