JSF 配置的 jsp 文件是 运行,但 xhtml 不是 运行

JSF configured jsp files are running, but xhtml are not running

我已经尝试了在 Whosebug 和其他论坛上看到的所有内容。没用。

运行 jsp 文件是正确的,但不是 xhtml 页面的新 facelets。

我关注了从 jsf1.x 到 2.x 的迁移线程:Migrating from JSF 1.2 to JSF 2.0

甚至过滤器也可以在简单的 jsp 实现中工作,在这里我尝试删除过滤器,它仍然无法工作。甚至无法找出错误。

错误:

exception 

javax.servlet.ServletException
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:230)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


root cause 

java.lang.WhosebugError
    java.net.URLStreamHandler.parseURL(Unknown Source)
    java.net.URL.<init>(Unknown Source)
    java.net.URL.<init>(Unknown Source)
    org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:314)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.getRelativePath(DefaultFacelet.java:470)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:552)
    org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:240)
    org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:151)
    org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:59)
    org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:48)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:521)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:575)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:553)
    org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:240)
    org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:151)
    org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:59)
    org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:48)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:521)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:575)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:553)
    org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:240)
    org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:151)
    org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:59)
    org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:48)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:521)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:575)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:553)
    org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:240)
    org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:151)
    org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:59)
    org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:48)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:521)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:575)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:553)
    org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:240)
    org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:151)
    org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:59)
    org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:48)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:521)
    org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:575)

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>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

</web-app>

home.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">

<body>
    <h:form>
    <center>

    <h:outputText value="#{loginMB.username}"></h:outputText>

    <h1>Welcome <h:outputText value="#{teamMB.teamHeadUsername}"></h:outputText></h1>
    <h:outputLink value="./login.jsf">Login as Team Admin</h:outputLink><br></br><br></br>
    <h:outputLink value="./registerteam.jsf" >Register your Team</h:outputLink><br></br><br></br>
    <h:outputLink value="./header.jsf">Header</h:outputLink><br></br><br></br>
    <h:outputLink value="./secure/dashboard.jsf">Dashboard</h:outputLink>

        </center>   
    </h:form>

</body>

<ui:composition template="">
    <ui:define name="header">
        Add your header here or delete to use the default
    </ui:define>
    <ui:define name="content">
        Add your content here or delete to use the default
    </ui:define>
    <ui:define name="footer">
        Add your footer here or delete to use the default
    </ui:define>
</ui:composition>
</html>

自己解决了。必须完全清空 faces-config.xml 文件,该文件以前填充了 managedBeans。

而且 xhtml 文件中的 ui:composition 标记也被删除,我认为这是主要问题。

我遇到了同样的问题。经过调查,我发现您提到的问题与 ui:composition 标签有关。它给出该错误的原因是没有定义模板文件。一旦我定义了一个,它就可以正常工作。