tomcat5应用移植到WAS5.1中的一些问题及解决
应用架构:
WebStart/jsp + struts1.1 + spring115 + hibernate2.1
1、由于was512不支持jstl2.0,因此,使用它时(当前可能在login.jsp和
其的统计页面中用到),需要web.xml中增加配置,或直接写明使用:
<%@ taglib uri="/WEB-INF/tld/c-1_0.tld" prefix="c" %>
而不是2.0
在web.xml中增加如下即可
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tld/c-1_0.tld</taglib-location>
</taglib>
如果支持,则可以直接用而不需要配置!
注意:jstl并不是WEB容器必须支持的东东!
3、session行不通呀:
这是我在BBS上提的问题:
我用URLConnection调用Servlet,有两种方法设置我当前的SESSION(后端传过来的):
设置Cookie的:JSESSIONID
或重写URL:http://localhost:9080/myapp/getList.do;jsessionid=-JW0T70Esp9QZlyfUKOsO7o?current=PEK
这在tomcat完全没有问题
但在WebSphere5.1下却不行,到服务器又创建了一个新的SESSION,不知道为什么?
安j2ee规范中,WEB容器必须支持这两种方式呀!帮帮我呀,谢谢。
还好,很快我就自己解决了,当然,主要还是看了IBM相关BBS上的信息才解决的。
可考虑:
一般而言,有两种最常用的会话跟踪机制,一种就是URL重写。在客户端不接受cookie的情况下可以使用URL重写进行会话跟踪。
URL重写包括向URL路径添加一些容器可以解释的数据。规范要求会话ID必须编码在URL路径中,参数名称必须是jsessionid,
例如: http://www.myserver.com/catalog/index.html;jsessionid=1234
一种就是现在最常用的cookie了,规范要求所有的servlet都必须支持cookie。容器向客户端发送一个cookie,
客户端在后续的处于同一个会话的请求中向服务器返回该cookie。会话跟踪cookie的名字必须是JSESSIONID。
httpUrl=http://localhost:9080/Agile/getFlightList.do;jsessionid=-JW0T70Esp9QZlyfUKOsO7o?currentCity=PEK
上面的方式也不行,也不知道还需要做什么设置?
好象是在WAS中,SESSIONID不止这些,而应该是:<your_session>:<websphere_clone_id>,而返回的只有:前的部分,当然没有呀!!
看下面的日志:
swt process,sessionID is :uEVqj3UC4yYmIAZvmyZzuPw
2005-06-21 13:24:06 [com.ibatis.struts.SwtAction]-[DEBUG]
other:0000uEVqj3UC4yYmIAZvmyZzuPw:-1,JSESSIONID=0000uEVqj3UC4yYmIAZvmyZzuPw:-1
2005-06-21 13:24:06 [com.ibatis.struts.SwtAction]-[DEBUG] cookie:JSESSIONID=0000uEVqj3UC4yYmIAZvmyZzuPw:-1
在链接页面中,代码如下:
<%
String sessionid = "";
Cookie[] cookie = request.getCookies();
for(int i = 0; i < cookie.length; i++)
{
if(cookie[i].getName().trim().equalsIgnoreCase("JSESSIONID"))
{
sessionid = cookie[i].getValue().trim();
break;
//logger.debug("cookie:"+cookie[i].getName() + "=" +cookie[i].getValue());
}
}
%>
<a href="/app/swt/index.jnlp?sessionid=<%=sessionid%>">lanuch client here</a>
实际上,解决此方法唯一要改的地方就是链接处(见上):
但为了以后其它的兼容性,将URL重写也加上,这在HTTPUTIL文件中。
即不能通过调用getSession().getId()得到,而应该自己从Cookie中找
5、ORB得不到,也无法得到SUN的ORB,好象他用的是JDK1.4.1,还是是SUN的,可以试试更换JRE看看,另外,如果真上WAS的话,应该用
更好的方式去调用TUXEDO,而不是现在的方式!
答:将Jre1.4.2下的rt.jar拷到WAS的JRE的LIB/EXT下即可,为防止冲突,要将java/javax下的全删掉,注意,这个方法不行,类型转换时
会有问题。
最终可以了,好象是测试时TUXEDO端有问题,同时,还改了如下代码:
通过JNDI得到:
orb = (org.omg.CORBA.ORB) ctx.lookup("java:comp/ORB");
orb =(org.omg.CORBA.ORB)javax.rmi.PortableRemoteObject.narrow(
ctx.lookup("java:comp/ORB"),
org.omg.CORBA.ORB.class);
应该不改也可以的!
是这以前出现的异常:
JNDI:
org.omg.CORBA.INTERNAL: vmcid: 0x4f422000 minor code: 77 completed: No
6、有关InitServlet晚于listener执行的问题,解决无非两程:
1)让Spring在需要时才生成对象
2)自己写listener载入配置(不在InitServlet中进行),且必须在Spring的listener之前执行。
3)规定不要在SPRING管理的类构造函数中调用配置。
先安3)去做,以后有时间再照前两种。
以下是IBM BBS上的一些问答,供参考:
附录:
um=266#4023650
JSESSIONID cookie - Help!
Originally posted: 2004 July 15 05:39 AM
Nau Post new reply
Hi, All
I have a need to call a servlet from another one withing the same session:
URL url = new URL( someURL );
URLConnection connection = url.openConnection();
connection.setDoInput( true );
connection.setRequestProperty( "Cookie", "JSESSIONID=" + request.getSession().getId() );
This piece of code works fine for Tomcat but on Webspere I'm getting a new session.
Any help please!
Thanks a million
Re: JSESSIONID cookie - Help!
Originally posted: 2004 July 19 07:15 AM
Ben_ Post new reply
WebSphere generates a cookie named JSESSIONID with value
<your_session>:<websphere_clone_id>.
It can be JSESSIONID=000024N1ZDMZZH022EANUW2ZO5I:u7078j8m, for example.
You can see this if you look at the cookies the browser received or dump the
HTTP request headers.
You built an HTTP request containing the JSESSIONID cookie with
"JSESSIONID=" + request.getSession().getId(), but this code is broken
because getSession().getId() only return the value before the ':' sign in
the cookie value.
Since only the *name* of the cookie is standardized in J2EE (JSESSIONID),
it's a bad idea to assume the format of the cookie is simply the session id,
because the way the *value* of the session cookie is computed is not J2EE
standardized.
You'd better read the actual value from the HTTP request header instead.
Re: JSESSIONID gets overwritten
Originally posted: 2005 Feb 28 05:01 PM
sjostrand2@hotmail.com Post new reply
Lukasz Szelag wrote:
> JSESSIONID gets overwritten in the following scenario:
>
> 1. HTTP Request is sent to "A" URL.
>
> 2. HTTP session is created for "A" and session ID is stored in
> JSESSIONID cookie.
>
> 3. "A" stores an object in the session.
>
> 4. "A" calls "B" ("B" provides a menu)
>
> 5. HTTP session is created for "B" and session ID is stored in
> JSESSIONID cookie overwriting the previous value ("A" session ID).
>
> 6. Second HTTP request is sent to "A" URL.
>
> 7. "A" fails to lookup the object in the session stored in step 3.
> request.getSession(false) returns null.
>
> Is there a way to cure this problem? Thanks.
>
> PS. Not sure if that matters but "A" and "B" are deployed on two
> different servers. Specifying a different names for cookies seems to
> help, i.e. JSESSIONID_A and JSESSIONID_B but this is WebSphere
specific
> extension (Servlet specification requires that the cookie name is
> JSESSIONID).
>
> Lukasz
I assume that A and B are in two different WAR files and therefore have
different context roots, right?
In that case you could use WebSphere's admin console and change the
cookie path from the default (which is /, meaning the cookie is sent as
long as the URL starts with a /, which is always) to the context root
for each application.
So for application A, set the cookie path to /appA_contextRoot and for
application B, set the cookie path to /appB_contextRoot.
In WebSphere's admin console, go to Enterprise Applications ->
Application A -> Session Management -> {click the Enable Cookies link}
and change the Cookie path.
Good luck
/Henrik Sjostrand
http:
accept : image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint,
application/msword, application/vnd.ms-excel, */*
accept-language : zh-cn
accept-encoding : gzip, deflate
user-agent : Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
host : localhost:9080
connection : Keep-Alive