文档详情

将应用从WebLogic 6.1移植到WebSphere 5 之 Web Application 篇.doc

发布:2017-12-17约1.05万字共9页下载文档
文本预览下载声明
将应用从WebLogic 6.1移植到WebSphere 5 之 Web Application 篇 简介 尽管WebSphere/WebLogic都是J2EE应用服务器,但是由于J2EE标准本身的原因,以及不同应用服务器提供不尽相同的特性,而程序员在开发应用的时候又没有考虑到应用要兼容不同应用服务器,这就出现了J2EE应用在不同应用服务器上的移植问题。 下面介绍我们在把J2EE Web应用从WebLogic移植WebSphere应用服务器过程中遇到的一些问题和解决办法。 至于更详细的系统环境准备,移植步骤等细节,请参考IBM红皮书,如Migrating WebLogic Applications to WebSphere V5, REDP0448。 一、Servlet/JSP移植问题 WebSphere 4/5和WebLogic 6.1应用服务器中的JSP编译器对于空对象(null String, null object等)的处理是不同的。 在Welbogic 6.1当中,如果字符串为null,或者对象为null,那么使用PrintWriter输出该对象的时候,输出的是长度为0的字符串;而在WebSphere 4/5、Tomcat 4.1以及WebLogic 7.0当中是输出了长度为4的字符串null。 下面servlet/jsp的例子在WebLogic 6.1/WebSphere中的运行结果是截然不同的。 servlet测试代码: java.io.PrintWriter out = response.getWriter(); out.println(null); jsp测试代码: % String s = null; % %=s% 或者 % Integer i = null; % %=i% 解决办法1: 所有要在Servlet/JSP输出的对象都有初始值,换言之就不会有输出空对象的情况。这样在servlet/jsp当中通过PrintWriter输出对象的时候就不会出现null字样。 解决办法2: 如果整个Web应用已经编写完毕,没有时间去修改包含业务逻辑的代码,那么可以使用如下的类(java class)处理servlet/jsp的输出。对于jsp页面通常可以通过手工替换%=为%=NullObject.get(,替换%为)%。 package utils; public class NullObject { public static String get(String o) { return (o == null) ? : o; } public static Integer get(Integer o) { return (o == null) ? new Integer(0) : o; } public static Long get(Long o) { return (o == null) ? new Long(0) : o; } public static Object get(Object o) { return (o == null) ? : o; } } 比如jsp代码片断%=s%可以修改为%=NullObject.get(s))% 注:在Java Language Specification [sec String Conversion]中写到 If the reference is null, it is converted to the string null (four ASCII characters n, u, l, l). Otherwise, the conversion is performed as if by an invocation of the toString method of the referenced object with no arguments; but if the result of invoking the toString method is null, then the string null is used instead. The toString method is defined by the primordial class Object; many classes override it, notably Boolean, Character, Integer, Long, Float, Double, and String. 二、JNDI移植问题 2.1 上下文工厂 J2EE程序在访问不同J2EE应用服务器名字空间的时候,需要指定相应服务器的名字空间上下文的工厂class名称,名字空间提供者的
显示全部
相似文档