tomcat5应用移植到WAS5.1中的一些问题及解决
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
1)讓Spring在需要時才生成對象
2)自己寫listener載入配置(不在InitServlet中進行),且必須在Spring的listener之前執行。
3)規定不要在SPRING管理的類構造函數中調用配置。
先安3)去做,以后有時間再照前兩種。
以下是IBM BBS上的一些問答,供參考:
附錄:
http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?message=4023650&cat=9&thread=54497&treeDisplayType=threadmode1&for
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
總結
以上是生活随笔為你收集整理的tomcat5应用移植到WAS5.1中的一些问题及解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IBM技术大会2005
- 下一篇: 0621