---
title: "PageContext在websphere和Tomcat的不同实现"
author: "seaman"
date: "2006-12-27T20:12:48Z"
tags: []
slug: "pagecontext-websphere-tomcat"
draft: false
lastmod: "2006-12-27T20:12:48Z"
id: 41071
url: "https://seaman.iteye.com/blog/41071"
---

今天碰到一个奇怪的问题，明明本地上好好的页面扔到服务器上就是通不过，搞了半天，才发现是was 与tomcat 的差异造成的。

    跟踪到出错的位置，JSP代码如下：

java 代码

1. String parentBSID = (String)request.getAttribute("parentBSID");
2. pageContext.setAttribute("parentBSID", parentBSID);

在百度上搜索websphere pageContextImpl.setAttribute null，居然一无所获；google 搜出来的几个页面慢得跟蜗牛一样，没办法只能靠自己。反编译tomcat与websphere应用服务器上对应的PageContextImpl类，结果如下：

tomcat 的standard.jar包中对PageContextImpl的实现是：

java 代码

1. mPage = Collections.synchronizedMap(new HashMap());

而was 的webcontainer.jar中对PageContextImpl的实现是：

java 代码

1. 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.”

问题解决，可能很多人已经发现了这个差异，但我搜索不到，所以写在这给有需要的人作个参考吧。