关于startup in wls8.....

请教各位高手:我在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
作者Re:[求救]把JSF的web应用从Tomcat移植到WLS8.1出错? [Re:liujun_css]
harvshen





发贴: 122
积分: 40
于 2004-05-11 22:32 user profilesend a private message to usersearch all posts byselect and copy to clipboard.
            ie only, sorry for netscape users:-)add this post to my favorite list
其实这是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 user profilesend a private message to usersearch all posts byselect and copy to clipboard.
            ie only, sorry for netscape users:-)add this post to my favorite list
多谢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 的数.

你说的方法我也试过了,完全可以.
若有什么新的进展或发现,请及时回帖,再次感谢.




哎,有点想换工作了……
作者Re:[求救]把JSF的web应用从Tomcat移植到WLS8.1出错? [Re:liujun_css]
liujun_css



发贴: 0
积分: 0
于 2004-05-27 09:35 user profilesend a private message to usersearch all posts byselect and copy to clipboard.
            ie only, sorry for netscape users:-)add this post to my favorite list
错了,加入的是 这句话
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
而不是
<init-param>
<param-name>CONFIGURE_LISTENER</param-name>
<param-value>com.sun.faces.config.ConfigureListener</param-value>
</init-param>

哈哈



 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值