java - JSF/小面 : CSS file resource is not found

标签 java css jsf

我正在尝试构建一个简单的 JSF 应用程序,但是当我使用下面的代码在 template/basic.xhtml 中添加 css 时,应用程序服务器(tomcat 7 和 glassfish 4)解析为 RES_NOT_FOUND

<h:head>
    <title><ui:insert name="title">Enrollment System</ui:insert></title>
    <h:outputStylesheet library="common" name="css/reset.css" />
    <h:outputStylesheet library="common" name="css/common.css" />
</h:head>

index.xhtml 只包含

<!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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="/templates/basic.xhtml">
    <ui:define name="content">
        <h1>Welcome, #{loginSession.privilege}</h1>
    </ui:define>
</ui:composition>
</html>

我已经阅读了另外几篇文章以及 Mkyong's JSF tutorial我应该将 css 放在某个特定的目录中,但仍然无法使其工作。

以下是我的文件所在的位置:

enrollment/index.xhtml
enrollment/WEB-INF/templates/basic.xhtml
enrollment/resources/common/css/reset.css
enrollment/resources/common/css/common.css

是否缺少任何其他配置以使其正常工作?

这是我在生成并返回 null ResourceInfo 的堆栈中找到的内容。

Daemon Thread [http-bio-80-exec-3] (Suspended)  
owns: SocketWrapper<E>  (id=62) 
ResourceManager.findResource(String, String, String, boolean, FacesContext) line: 190   
ResourceManager.findResource(String, String, String, FacesContext) line: 180    
ResourceHandlerImpl.createResource(String, String, String) line: 201    
ResourceHandlerImpl.createResource(String, String) line: 181    
StylesheetRenderer.encodeEnd(FacesContext, UIComponent) line: 97

getFromCache 将使用提供的四个参数在 HashMap 中搜索。

ResourceInfo info = getFromCache(resourceName, libraryName, localePrefix, contracts);

我已经检查了 HashMap 中的所有值,只有两个资源,即

"/"
"/WEB-INF/templates/basic.xhtml"

这可能是因为资源从未添加到 HashMap 中的原因

最佳答案

我意外地解决了这个问题。

修复是在创建元素时不要选择“生成 web.xml 部署描述符”。

关于java - JSF/小面 : CSS file resource is not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17625362/

相关文章:

java - 为什么我不能创建内部类的实例?

java - 引用文件路径时出现filenotfoundexception

javascript - 脚本在 jsfiddle 中工作而不是在静态文件中?

循环内的 ADF Faces 1.1 JavaScript

jsf - JSF 中 UIComponent 的值和绑定(bind)标记之间的差异

java - 我应该如何在 Android Studio 3.0.1 中导出到 zip 文件

Java ServerSocket OutputStream 不刷新

html - 如果空间足够则并排 div,否则以 100% 宽度堆叠

css - gitk时CFURLCopyResourcePropertyForKey错误

jsf - 将方法参数/参数传递给复合组件操作属性