不可能吧, 不在WEB.xml里面配置是不可能被调用的,j2ee2.4的examples里面的配置里面有<listener>
 <listener-class>listeners.ContextListener</listener-class>
</listener>
这段。

解决方案 »

  1.   

    <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup> 1 </load-on-startup>
      

  2.   

    的确没有配子哈监听器,下面就是demo的例子<!DOCTYPE web-app PUBLIC
      "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
      "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>    <display-name>JavaServer Faces Guess Number Sample Application</display-name>
        <description>
            JavaServer Faces Guess Number Sample Application
        </description>    <context-param>
            <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
            <param-value>client</param-value>
        </context-param>    <context-param>
            <param-name>com.sun.faces.validateXml</param-name>
            <param-value>true</param-value>
            <description>
                Set this flag to true if you want the JavaServer Faces
                Reference Implementation to validate the XML in your
                faces-config.xml resources against the DTD.  Default
                value is false.
            </description>
        </context-param>    <context-param>
            <param-name>com.sun.faces.verifyObjects</param-name>
            <param-value>true</param-value>
            <description>
                Set this flag to true if you want the JavaServer Faces
                Reference Implementation to verify that all of the application
                objects you have configured (components, converters,
                renderers, and validators) can be successfully created.
                Default value is false.
            </description>
        </context-param>    <!-- Faces Servlet -->
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup> 1 </load-on-startup>
        </servlet>
        <!-- Faces Servlet Mapping -->
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>/guess/*</url-pattern>
        </servlet-mapping>    <security-constraint>
     <!-- This security constraint illustrates how JSP pages 
                 with JavaServer Faces components can be protected from
                 being accessed without going through the Faces Servlet.
                 The security constraint ensures that the Faces Servlet will
                 be used or the pages will not be processed. -->
    <display-name>Restrict access to JSP pages</display-name>
    <web-resource-collection>
                <web-resource-name>
    Restrict access to JSP pages
                </web-resource-name>
        <url-pattern>/greeting.jsp</url-pattern>
        <url-pattern>/response.jsp</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <description>
    With no roles defined, no access granted
        </description>
    </auth-constraint>
        </security-constraint></web-app>
      

  3.   

    因为没有配置监听器所以对JSF的FactoryFinder到底是如何找到JSF实现类感到困惑。 FacesServlet的一个facesContextFactory = (FacesContextFactory) 
    FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);就和sun的实现发生绑定了,到底它是怎么知道在哪里加载sun的实现类的呢?
      

  4.   

    JSF1.1的sun实现的guessNumber的例子 web.xml代码:  
    <!DOCTYPE web-app PUBLIC 
      "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
      "http://java.sun.com/dtd/web-app_2_3.dtd"> 
    <web-app>     <display-name>JavaServer Faces Guess Number Sample Application</display-name> 
        <description> 
            JavaServer Faces Guess Number Sample Application 
        </description>     <context-param> 
            <param-name>javax.faces.STATE_SAVING_METHOD</param-name> 
            <param-value>client</param-value> 
        </context-param>     <context-param> 
            <param-name>com.sun.faces.validateXml</param-name> 
            <param-value>true</param-value> 
            <description> 
                Set this flag to true if you want the JavaServer Faces 
                Reference Implementation to validate the XML in your 
                faces-config.xml resources against the DTD.  Default 
                value is false. 
            </description> 
        </context-param>     <context-param> 
            <param-name>com.sun.faces.verifyObjects</param-name> 
            <param-value>true</param-value> 
            <description> 
                Set this flag to true if you want the JavaServer Faces 
                Reference Implementation to verify that all of the application 
                objects you have configured (components, converters, 
                renderers, and validators) can be successfully created. 
                Default value is false. 
            </description> 
        </context-param>     <!-- Faces Servlet --> 
        <servlet> 
            <servlet-name>Faces Servlet</servlet-name> 
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
            <load-on-startup> 1 </load-on-startup> 
        </servlet> 
        <!-- Faces Servlet Mapping --> 
        <servlet-mapping> 
            <servlet-name>Faces Servlet</servlet-name> 
            <url-pattern>/guess/*</url-pattern> 
        </servlet-mapping>     <security-constraint> 
            <!-- This security constraint illustrates how JSP pages 
                 with JavaServer Faces components can be protected from 
                 being accessed without going through the Faces Servlet. 
                 The security constraint ensures that the Faces Servlet will 
                 be used or the pages will not be processed. --> 
            <display-name>Restrict access to JSP pages</display-name> 
            <web-resource-collection> 
                <web-resource-name> 
                    Restrict access to JSP pages 
                </web-resource-name> 
                <url-pattern>/greeting.jsp</url-pattern> 
                <url-pattern>/response.jsp</url-pattern> 
            </web-resource-collection> 
            <auth-constraint> 
                <description> 
                    With no roles defined, no access granted 
                </description> 
            </auth-constraint> 
        </security-constraint> </web-app> 
     
    上面并没有配置监听器,但是看看下面的内容Thread: main
       <init>() : 98, com.sun.faces.application.ApplicationAssociate, ApplicationAssociate.java
       <init>() : 98, com.sun.faces.application.ApplicationImpl, ApplicationImpl.java
       getApplication() : 74, com.sun.faces.application.ApplicationFactoryImpl, ApplicationFactoryImpl.java
       application() : 384, com.sun.faces.config.ConfigureListener, ConfigureListener.java
       configure() : 427, com.sun.faces.config.ConfigureListener, ConfigureListener.java
       configure() : 402, com.sun.faces.config.ConfigureListener, ConfigureListener.java
       contextInitialized() : 332, com.sun.faces.config.ConfigureListener, ConfigureListener.java ---------是一个监听器
       listenerStart() : 3669, org.apache.catalina.core.StandardContext, StandardContext.java
       start() : 4104, org.apache.catalina.core.StandardContext, StandardContext.java
       start() : 1012, org.apache.catalina.core.ContainerBase, ContainerBase.java
       start() : 718, org.apache.catalina.core.StandardHost, StandardHost.java
       start() : 1012, org.apache.catalina.core.ContainerBase, ContainerBase.java
       start() : 442, org.apache.catalina.core.StandardEngine, StandardEngine.java
       start() : 450, org.apache.catalina.core.StandardService, StandardService.java
       start() : 683, org.apache.catalina.core.StandardServer, StandardServer.java
       start() : 537, org.apache.catalina.startup.Catalina, Catalina.java
       invoke0() : -1, sun.reflect.NativeMethodAccessorImpl, NativeMethodAccessorImpl.java
       invoke() : 39, sun.reflect.NativeMethodAccessorImpl, NativeMethodAccessorImpl.java
       invoke() : 25, sun.reflect.DelegatingMethodAccessorImpl, DelegatingMethodAccessorImpl.java
       invoke() : 585, java.lang.reflect.Method, Method.java
       start() : 271, org.apache.catalina.startup.Bootstrap, Bootstrap.java
       main() : 409, org.apache.catalina.startup.Bootstrap, Bootstrap.java这个web.xml没有配置监听器为什么监听器ConfigureListener还是能被调用呢?