项目从tomcat迁移到weblogic环境下问题汇总----不断补充中ing

在将项目从Tomcat迁移到WebLogic过程中,遇到了关于web app root system property设置的问题,导致DeploymentException。主要原因是WAR文件未展开,无法设置系统属性。解决方案包括检查web.xml中的webAppRootKey唯一性和配置WebLogic的container-descriptor。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                1、 JDK和Servlet版本问题 

WebLogic 8.1 sp4以前(包括sp4)只支持JDK1.4,建议使用JDK1.4进行编译代码,有时JDK1.5编译的程序无法运行,由于WebLogic 8.1不支持J2EE1.4,不要使用Servlet2.4和JSP2.0进行编码。 

比如:在tomcat下代码里中可以有response.setCharacterEncoding("UTF-8")方法,这是servlet2.4的方法,所以要发布到weblogic上需要把此方法注释掉。 

另外关于查看weblogic支持的servlet版本方法如下: 
Java代码   收藏代码
  1. javax.servlet.ServletContext   
  2.   
  3. getMajorVersion()  //主版本号(2)  
  4. getMinorVersion()  //次版本号 (3)  

结果分别为2、3的话就说明,版本号为 servlet2.3 


2、 web.xml 中的启动加载问题 

在TOMCAT中,加载Struts的顺序是通过servlet加载,排在Listener加载之后。如果在Struts中使用Plugin,会在TOMCAT启动的最后加载,所以在Plugin中可以使用Spring中的Bean。 

移植到WebLogic后,Struts会在容器启动的时候全部加载,包括Plugin。这样就出现了在Plugin加载的时候,不能得到 Spring管理的Bean,也就是说Struts Plugin在WebLogic里不能使用Spring管理的Bean。所以如果需要启动时加载部分代码,建议使用Servlet init()方法。 

Spring为通过Web启动的程序提供了一个工具,该工具可以从Context中直接得到WebApplicationContext,其工具的方法签名如下: 
Java代码   收藏代码
  1. org.springframework.web.context.support.WebApplicationContextUtils. getWebApplicationContext(ServletContext);     
  2.   
  3. org.springframework.web.context.support.WebApplicationContextUtils. getWebApplicationContext(ServletContext);  


3、 JSP 的 Include问题  (建议使用动态引入)  

在BEA WebLogic中不允许在一个文件中出现一次以上类似<%@ page contentType="text/html; charset=GBK"%>的代码,所以使用include file时,请将被include的文件中类似代码删除。 

在TOMCAT时允许上述代码出现多回,并且使用include file时,被include的文件中,不包含上述代码,编译后客户端显示为乱码。BEA为此解释为TOMCAT不符合J2EE规范。 

为了增加代码的通用性和可移植性,建议使用<jsp:include>方式。 
<jsp:include>将被include的jsp代码视为独立存在的文件,所以可以在不同文件内使用多个<%@ page contentType="text/html; charset=GBK"%>。<jsp:include>直接传参由<jsp:param>标签完成,在被 include页面可以通过request得到传入的值,也可以通过request.setAttribute()、 request.getAttribute()进行内外文件参数传递。


4、 对Log4j支持问题 

打包成.war部署到WebLogic后,出现如下问题: 
Java代码   收藏代码
  1. Error: weblogic.management.DeploymentException: Cannot set web app root system property when WAR file is not expanded - with nested exception:      
  2.     
  3. [java.lang.IllegalStateException: Cannot set web app root system property when WAR file is not expanded]     
  4.   
  5. Error: weblogic.management.DeploymentException: Cannot set web app root system property when WAR file is not expanded - with nested exception:   
  6.   
  7. [java.lang.IllegalStateException: Cannot set web app root system property when WAR file is not expanded]   


问题解决:通常您不需要亲自编写servlet或者listener,比如直接利用log4j的 com.apache.jakarta.log4j.Log4jInit类,Spring的 org.springframework.web.util.Log4jConfigServlet和 org.springframework.web.util.ServletContextListener方式配置,找到.Log4jConfigServlet和ServletContextListener的源码,他们都在适当的地方(callback method)调用了Log4jWebConfigurer.initLogging(getServletContext());定位到这个方法,第一句就是:WebUtils.setWebAppRootSystemProperty(servletContext);再定位到该方法,方法很短: 

Java代码   收藏代码
  1. public static 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值