![](/img/trans.png)
[英]How to get Glassfish to automatically “find” the index.xhtml and render it through JSF
[英]JSF pages not being executed except index.xhtml
我正在學習帶有Primefaces的Java Web和jsf。
我的項目當前只有一個index.xhtml文件,當我訪問localhost:8080 / appname / index.xhtml時,將正確執行, 但是當我訪問localhost:8080 / appname / index.xhtml時 ,應用程序服務器將返回jsf源代碼。
另外,faces /目錄上的任何xhtml文件都將返回以下錯誤:
com.sun.faces.context.FacesFileNotFoundException: /face.xhtml Not Found in ExternalContext as a Resource
at com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:274)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:357)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:250)
at com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:113)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:241)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
/index.xhtml:
<?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"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<p:clock/>
</h:body>
</html>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Appname</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<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>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
</web-app>
添加的應用程序樹:
.
├── faces
│ └── face.xhtml
├── faces.jsf
├── index.xhtml
├── META-INF
│ ├── context.xml
│ └── MANIFEST.MF
└── WEB-INF
├── classes
│ ├── ...
├── glassfish-web.xml
├── lib
│ ├── ...
└── web.xml
您需要調用FacesServlet ,因為web.xml中的映射顯示
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
嘗試訪問URL中帶有面孔的頁面
本地主機:8080 / appname / 面對 /index.xhtml
如我所見,您有一個名為faces的文件夾。 您必須更改此文件夾名稱,因為該名稱保留給servlet URL映射。
即使您嘗試通過調用localhost:8080 / appname / faces / faces / index.xhtml來訪問face.xhtml,也將無法訪問它。
假設您將文件夾“ faces”更改為webFaces,然后將訪問該頁面
localhost:8080/appname/faces/webFaces/index.xhtml
希望能有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.