在ExternalContext中找不到/index.xhtml作为资源

Raf*_*uza 11 jsf jsf-2

我的JSF Web应用程序显示以下错误:

在ExternalContext中找不到/index.xhtml作为资源.

我的目录结构是:

- Java Resource
-- src
--- br.com.k19.controle
---- NumeroAleatorioBean.java
--- resources
- JavaScript Resources
- build
- WebContent
-- META-INF
-- Web Pages
--- index.xhtml
--- formulario.xhtml
-- Web-Inf

我需要把我/index.xhtml的这个结构放在哪里?

Bal*_*usC 16

WebContent文件夹代表Web内容.您将index.xhtml文件放在Web Pages子文件夹中,以便正确的URL

http://localhost:8080/ProjectName/Web Pages/index.xhtml
Run Code Online (Sandbox Code Playgroud)

因此不是

http://localhost:8080/ProjectName/index.xhtml
Run Code Online (Sandbox Code Playgroud)

正如你所期待的那样.

如果你想拥有它的上下文根,刚摆脱了Web Pages文件夹完全,然后将这些.xhtml文件直接里面WebContent的文件夹,在同级别META-INFWEB-INF:

ProjectName
 |-- Java Resources
 |    `-- src
 |         `-- br.com.k19.controle
 |              `-- NumeroAleatorioBean.java
 |-- resources
 |-- JavaScript Resources
 |-- build
 `-- WebContent
      |-- META-INF
      |-- WEB-INF
      |    |-- faces-config.xml
      |    `-- web.xml
      |-- index.xhtml
      `-- formulario.xhtml
Run Code Online (Sandbox Code Playgroud)

注意:Java区分大小写.Web-Inf绝对不一样WEB-INF.小心,否则你会有安全漏洞.

  • `Webcontent`或`WebContent`?套管有所不同.您是否重建/重新部署/重新启动项目和服务器?`*.xhtml`模式很好.我删除了`/ faces/*`模式,它是JSF 1.0中一个无用的剩余,并没有真正推荐,因为它只会引起初学者之间的混淆. (4认同)