请教各位高手:我在Tomcat4.0下做了一个简单的javaserver faces的应用,配置正确,运行没问题现. 在将它移植到Weblogic8.1下,结果报错:
Servlet: "Faces" failed to preload on startup in Web application: "WebModule1"
web.xml配置文件如下:
<context-param>
<param-name>saveStateInClient</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.application.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<servlet>
<servlet-name>Faces</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
...................................................
各位能否帮助一下,不胜感激.
• CJSDN in London
Servlet: "Faces" failed to preload on startup in Web application: "WebModule1"
web.xml配置文件如下:
<context-param>
<param-name>saveStateInClient</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.application.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<servlet>
<servlet-name>Faces</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
...................................................
各位能否帮助一下,不胜感激.
• CJSDN in London
作者 | Re:[求救]把JSF的web应用从Tomcat移植到WLS8.1出错? [Re:liujun_css] |
harvshen 发贴: 122 积分: 40 | 于 2004-05-11 22:32
其实这是weblogic的一个bug,或者说是JSF的BUG listener ordering is not part of the Servlet 2.3 spec,but JSF made a assumption here. ===check the explanation here== The issue seems to be Weblogic is not respecting part of the Servlet 2.3 spec. It states that all ServletContextListener implementations should be called before the Servlet's init method is called. Tomcat respects this and that's why JSF works when deployed in Tomcat. Weblogic 8.1 calls this instance AFTER the Servlet's init's methods are called. This results in a NullPointerException being thrown. You can see how the ordering changes between Weblogic and Tomcat for yourself by editing the log4j.properties file and add the following: log4j.category.com.sun.faces.config = DEBUG, config log4j.additivity.com.sun.faces.config=false log4j.appender.config = org.apache.log4j.ConsoleAppender log4j.appender.config.layout = org.apache.log4j.PatternLayout log4j.appender.config.layout.ConversionPattern = ... Deploy the example application to both Weblogic and Tomcat and observe the order. I've developed a work around for this issue. Weblogic seems to respect the <load-on-startup> element in the web.xml file. I have written a Servlet which manually loads the ServletContextListener for JSF. The code below: import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import javax.faces.FactoryFinder; import javax.faces.lifecycle.LifecycleFactory; import javax.servlet.ServletConfig; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; public class WeblogicHackServlet extends HttpServlet { public static final String CONFIGURE_LISTENER_KEY = "CONFIGURE_LISTENER"; public static final transient Log logger = LogFactory.getLog(WeblogicHackServlet.class); public void init(ServletConfig servletConfig) throws ServletException { LifecycleFactory factory =(LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); if (factory != null) return; String className = servletConfig.getInitParameter(CONFIGURE_LISTENER_KEY); if (className == null) { logger.fatal("Did not find the init parameter " + CONFIGURE_LISTENER_KEY); return; } try { Class aClass = Class.forName(className); ServletContextListener listener = (ServletContextListener) aClass.newInstance(); listener.contextInitialized( new ServletContextEvent(servletConfig.getServletContext())); } catch (Exception e) { logger.fatal("The ConfigureListener could not be triggered", e); } } } The web.xml file also needs to be changed to the following: <servlet> <servlet-name>WeblogicHackServlet</servlet-name> <servlet-class>WeblogicHackServlet</servlet-class> <init-param> <param-name>CONFIGURE_LISTENER</param-name> <param-value>com.sun.faces.config.ConfigureListener</param-value> </init-param> <load-on-startup> 1 </load-on-startup> </servlet> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup> 2 </load-on-startup> </servlet> This causes JSF to load properly. Hopefully, BEA can resolve this issue so my hack can be removed. • 如何将这个程序改正到可以运行 |
作者 | Re:[求救]把JSF的web应用从Tomcat移植到WLS8.1出错? [Re:liujun_css] |
liujun_css 发贴: 0 积分: 0 | 于 2004-05-14 12:22
多谢harvshen,问题已经解决了,和你上面的方法有一些区别. 在web.xml中加入了 <init-param> <param-name>CONFIGURE_LISTENER</param-name> <param-value>com.sun.faces.config.ConfigureListener</param-value> </init-param> 再将 <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup> -1 </load-on-startup> </servlet> 的<load-on-startup> 元素的值改为 小于0 的数. 你说的方法我也试过了,完全可以. 若有什么新的进展或发现,请及时回帖,再次感谢. • 哎,有点想换工作了…… |