Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将自定义字体导入JSF_Java_Css_Jsf_Jsf 2_Fonts - Fatal编程技术网

Java 将自定义字体导入JSF

Java 将自定义字体导入JSF,java,css,jsf,jsf-2,fonts,Java,Css,Jsf,Jsf 2,Fonts,我无法将自定义字体导入我的JSF页面。项目结构如下所示: 我尝试在我的styles.css中编写以下内容: @font-face { font-family: "Gotham Pro Bold"; src: url('#{resource["fonts/GothaProBol.otf"]}'); } 但它不起作用。它被编译成/javax.faces.resource/fonts/GothaProBol.otf.xhtml,但字体不在ja

我无法将自定义字体导入我的JSF页面。项目结构如下所示:

我尝试在我的styles.css中编写以下内容:

@font-face {
    font-family: "Gotham Pro Bold";
    src: url('#{resource["fonts/GothaProBol.otf"]}');
}
但它不起作用。它被编译成
/javax.faces.resource/fonts/GothaProBol.otf.xhtml
,但字体不在
javax.faces.resource
中,我不知道它为什么会附加
.xhtml

以下是:

src: url("#{facesContext.externalContext.requestContextPath}/resources/fonts/GothaProBol.otf");
编译为

src: url("/resources/fonts/GothaProBol.otf");
但它也不起作用

如何正确导入字体

提前感谢。

使用以下方法完成此操作:

  • 添加了(
    pom.xml
    ):

    
    org.omnifaces
    全方位
    1.8.1
    

  • 将OmniFaces的资源处理程序添加到
    faces config.xml

    
    org.omnifaces.resourcehandler.UnmappedResourceHandler
    

  • /javax.faces.resource/*
    映射到
    FacesServlet
    ,如下(
    web.xml
    ):

    
    Facesservlet
    javax.faces.webapp.FacesServlet
    1.
    Facesservlet
    /javax.faces.resource/*
    *.xhtml
    

  • 在CSS中使用
    #{resource[“”]}
    ,如下所示:

    @font-face{
    字体系列:“Gotham Pro Bold”;
    src:url('#{resource[“font/GothaProBol.otf”]});
    }


  • 我发现这里有一个类似的问题,我不需要使用/javax.faces.resource/*。