Websphere与Tomcat的差异区别。
1、page Content-Type的问题
在tomcat中,如果a.jsp包含b.jsp,那么a.jsp和b.jsp两个文件上都要加上< %@ page contentType=”text/html;charset=GBK” % >,否则jsp页面上会出现中文乱码,然而在websphere上,如果a.jsp和b.jsp上都存在< %@ page contentType=”text/html;charset=GBK” % >的话,那么将抛出异常:不能出现多个 contentType’, 出现这种情况,
解决方法为:将b.jsp中的< %@ page contentType=”text/html;charset=GBK” % >去掉。
2、
- String parentBSID = (String)request.getAttribute(“parentBSID”);
- pageContext.setAttribute(“parentBSID”, parentBSID);
反编译tomcat与websphere应用服务器上对应的PageContextImpl类,结果如下:
tomcat 的standard.jar包中对PageContextImpl的实现是:
- mPage = Collections.synchronizedMap(new HashMap());
而was 的webcontainer.jar中对PageContextImpl的实现是:
- attributes = new Hashtable(16);
tomcat和websphere对pageContext的实现最关键的差别就是前者使用了HashMap,后者使用了Hashtable,Java API Document 对Hashtable.put(Object key,Object value)有明确说明:“Maps the specified key to the specified value in this hashtable. Neither the key nor the value can be null.”
3、カスタムタグのattributeで配列を使用する場合
type=”java.lang.String[]”
Tomcat ○
WAS ×
4,Javaプログラム中で、
WASの場合、以下の式
request.removeAttribute(name)
を実行する時、nameがnullだとNullPointerExceptionが発生する。
Tomcatの場合、上記例外は発生しないが、(上記例のnameがnullの可能性がある
場合には)下記のように実装する必要がある。
if (name != null) {
request.removeAttribute(name);
}
5,taglib妥当性検証エラー
c:choose, c:when, c:otherwise タグの記述方法について
一般的な記述の仕方:
<c:choose>
<c:when …>…</c:when>
<c:otherwise>…</c:otherwise>
</c:choose>
ただし、この場合無用な改行文字が多数出力される。
それを嫌って、以下のような記述が可能である。文法的にも問題ない。
<c:choose
><c:when …>…</c:when
><c:otherwise>…</c:otherwise
></c:choose>
Tomcatではこの記述で問題ないが、WASでは正しくパースできず、エラーとなる。
この問題を回避するため、
無用な改行文字の出力を抑止したい場合は、必要に応じて
<c:choose><c:when …>…</c:when><c:otherwise>…</c:otherwise></c:choose>
というように、間に改行を入れずに一行で記述する。