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版本方法如下:
结果分别为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,其工具的方法签名如下:
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后,出现如下问题:
问题解决:通常您不需要亲自编写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);再定位到该方法,方法很短:
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版本方法如下:
- javax.servlet.ServletContext
- getMajorVersion() //主版本号(2)
- 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,其工具的方法签名如下:
- org.springframework.web.context.support.WebApplicationContextUtils. getWebApplicationContext(ServletContext);
- 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后,出现如下问题:
- Error: weblogic.management.DeploymentException: Cannot set web app root system property when WAR file is not expanded - with nested exception:
- [java.lang.IllegalStateException: Cannot set web app root system property when WAR file is not expanded]
- Error: weblogic.management.DeploymentException: Cannot set web app root system property when WAR file is not expanded - with nested exception:
- [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);再定位到该方法,方法很短:
- public static