两个类似的项目:一个找到 CSS,另一个没有

发布于 2024-12-04 21:33:29 字数 2667 浏览 0 评论 0原文

我创建了两个 Netbeans 项目,并且在 web.xml 中具有相同的配置:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
   <servlet-name>Faces Servlet</servlet-name>
   <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

两者的 css 文件都具有以下目录结构:

<Root>\src\main\webapp\resources\css\styles.css

在 Facelets 模板中,在 部分中 当

<h:outputStylesheet name="styles.css" library="css" />

如果我解压它们各自的 .war 文件,则两者都有

<root>\resources\css\styles.css

我启动这些网络应用程序并通过 firebug 查看网页时,两者都会使用:

<root>javax.faces.resource/styles.css.xhtml

现在但是:一个找到了 css 文件,而另一个则没有。我在这里缺少什么?


更新:根据评论,我检查了CSS失败的项目的Firebug的Net选项卡。 CSS 请求/响应位于 HTML 选项卡而不是 CSS 选项卡内,并且响应标头具有 Content-Type: text/html; 并且响应正文是整个网页,而不仅仅是 CSS在工作项目中!

请求标头:

Host: mike-  
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2  
Accept: text/css,*/*;q=0.1  
Accept-Language: en-us  
Accept-Encoding: gzip, deflate  
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7  
Connection: keep-alive  
Referer: http://mike-6:8080/root/  
Cookie: JSESSIONID=fa60fb0becd860721422cad79e09

响应标头:

X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.1 Java/Sun Microsystems Inc./1.6), JSF/2.0  
Server: GlassFish Server Open Source Edition 3.1.1  
Pragma: No-cache  
Cache-Control: no-cache  
Expires: Wed, 31 Dec 1969 18:00:00 CST  
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked  
Date: Mon, 19 Sep 2011 03:06:22 GMT

响应正文:

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<link type="text/css" rel="stylesheet" href="/MyBills/javax.faces.resource/themes/sam/theme.css.xhtml?ln=primefaces&amp;amp;v=3.0.M2" />  
<link type="text/css" rel="stylesheet" href="/MyBills/javax.faces.resource/styles.css.xhtml?ln=css" />  
</head>  
   <body>  
           /* body is entire web page */  
   </body>  
</html>

I have created two Netbeans projects and both have the same configuration in web.xml:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
   <servlet-name>Faces Servlet</servlet-name>
   <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

Both have the following directory structure for the css file:

<Root>\src\main\webapp\resources\css\styles.css

In a facelets template, in the <h:head> section both have

<h:outputStylesheet name="styles.css" library="css" />

If I unzip their respective .war files, both have

<root>\resources\css\styles.css

When I launch these web apps and look at the web page thru firebug both use:

<root>javax.faces.resource/styles.css.xhtml

Now the BUT: one finds the css file and one does not. What am I missing here?


Update: As per the comments, I have checked the Net tab of Firebug of the project where the CSS fails. The CSS request/response is inside HTML tab instead of CSS tab and the response Header has Content-Type: text/html; and the response body is the entire web page rather than just the CSS like it is in the working project!

Request headers:

Host: mike-  
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2  
Accept: text/css,*/*;q=0.1  
Accept-Language: en-us  
Accept-Encoding: gzip, deflate  
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7  
Connection: keep-alive  
Referer: http://mike-6:8080/root/  
Cookie: JSESSIONID=fa60fb0becd860721422cad79e09

Response headers:

X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.1 Java/Sun Microsystems Inc./1.6), JSF/2.0  
Server: GlassFish Server Open Source Edition 3.1.1  
Pragma: No-cache  
Cache-Control: no-cache  
Expires: Wed, 31 Dec 1969 18:00:00 CST  
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked  
Date: Mon, 19 Sep 2011 03:06:22 GMT

Response body:

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<link type="text/css" rel="stylesheet" href="/MyBills/javax.faces.resource/themes/sam/theme.css.xhtml?ln=primefaces&amp;v=3.0.M2" />  
<link type="text/css" rel="stylesheet" href="/MyBills/javax.faces.resource/styles.css.xhtml?ln=css" />  
</head>  
   <body>  
           /* body is entire web page */  
   </body>  
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文