在线工具 在线编程 在线白板 在线工具 在线编程 在线白板

Websphere和Tomcat下使用PageContex有什么区别?

公司的开发环境用的是Tomcat,而测试环境用的则是Websphere6。
在开发过程中,某个Jsp文件使用了PageContex指定其属性:
default_value="<%=(String)((Model) pageContext.getAttribute("list")).getName()%>",调试没有问题,可是放到测试服务器上确无法解析,请问各位高手这是什么原因,应该怎么解决?
最新回答
荆棘里旳花ゝ

2024-11-22 14:18:09

PageContext在websphere和Tomcat的不同实现
关键字: PageContext

今天碰到一个奇怪的问题,明明本地上好好的页面扔到服务器上就是通不过,搞了半天,才发现是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.”

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