GlassFish 6.2.3 看不到 javax.faces.webapp.FacesServlet

GlassFish 6.2.3 does not see javax.faces.webapp.FacesServlet

我在本地计算机上使用 glassfish6.2.3。如果我将这些行添加到 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>/faces/*</url-pattern>
    </servlet-mapping>

然后出现以下错误:

java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1577) at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1427) at org.apache.catalina.core.StandardWrapper.loadServletClass(StandardWrapper.java:1391) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1257) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1239) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5343) at org.apache.catalina.core.StandardContext.start(StandardContext.java:5588) at com.sun.enterprise.web.WebModule.start(WebModule.java:510) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:877) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:860) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:644) at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2020) at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1666) at com.sun.enterprise.web.WebApplication.start(WebApplication.java:82) at org.glassfish.internal.data.EngineRef.start(EngineRef.java:98) at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:267) at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:328) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:480) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:199) at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:467) at com.sun.enterprise.v3.admin.CommandRunnerImpl.run(CommandRunnerImpl.java:516) at com.sun.enterprise.v3.admin.CommandRunnerImpl.run(CommandRunnerImpl.java:512) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/javax.security.auth.Subject.doAs(Subject.java:361) at com.sun.enterprise.v3.admin.CommandRunnerImpl.execute(CommandRunnerImpl.java:511) at com.sun.enterprise.v3.admin.CommandRunnerImpl.run(CommandRunnerImpl.java:542) at com.sun.enterprise.v3.admin.CommandRunnerImpl.run(CommandRunnerImpl.java:534) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/javax.security.auth.Subject.doAs(Subject.java:361) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:533) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1441) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1823) at org.glassfish.deployment.autodeploy.AutoOperation.run(AutoOperation.java:140) at org.glassfish.deployment.autodeploy.AutoDeployer.deploy(AutoDeployer.java:573) at org.glassfish.deployment.autodeploy.AutoDeployer.deployAll(AutoDeployer.java:460) at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:388) at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:379) at org.glassfish.deployment.autodeploy.AutoDeployService.run(AutoDeployService.java:209) at java.base/java.util.TimerThread.mainLoop(Timer.java:556) at java.base/java.util.TimerThread.run(Timer.java:506)

否则,一切正常,但不会显示 jsf 元素

GlassFish 6.2.3 实现了 Jakarta EE 9.1 和 Faces 3.0。它们使用 Jakarta 命名空间。因此,您的 servlet 声明应该是:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
</servlet>

请注意,除了在 web.xml 中定义 servlet,您还可以在应用程序中使用 @FacesConfig 注释。这会将您的所有视图默认映射到 .xhtml.