View Full Version : Why always change session id?
shjy.nicholas
03-14-2008, 05:36 AM
Dear, Everybody,
When i user Ext.Ajax.request, the server side always get a new session id.
Even a very simple case,
such as
Ext.Ajax.request({
url: '/test/testLogin/',
success: function() {alert('success')},
failure: function() {alert('failure')},
params: { uid: new Date().getTime(), uname: new Date().getTime() }
});
the server code:(Java Servlet)
System.out.println("Sesseion id: " + request.getSession().getId());
System.out.println("uid: " + request.getParameter("uid"));
System.out.println("uname: " + request.getParameter("uname"));
The terminal prints:
Sesseion id: 9CEA218F32ACF766B339EDD174FEBB04
uid: 1205486576312
uname: 1205486576312
Sesseion id: FFBD081EF41AE538B7168943460F8DBF
uid: 1205486583578
uname: 1205486583578
But, in my application,
First, I need send a ajax request to the server, in order to get a validate code as a picture,
Then, when submit, I need to check the validate code at the server side. But the check process needs the same session id when the first used.
Is there anybody know how to fix it? I'm waiting...
cerad
03-14-2008, 08:21 AM
Is your server sending back the session id in a cookie? You can use Firebug to see whats going on but it sounds like your server is never setting the initial session id.
michaelc
03-14-2008, 09:41 AM
Dear, Everybody,
When i user Ext.Ajax.request, the server side always get a new session id.
Even a very simple case,
such as
Ext.Ajax.request({
url: '/test/testLogin/',
success: function() {alert('success')},
failure: function() {alert('failure')},
params: { uid: new Date().getTime(), uname: new Date().getTime() }
});
the server code:(Java Servlet)
System.out.println("Sesseion id: " + request.getSession().getId());
System.out.println("uid: " + request.getParameter("uid"));
System.out.println("uname: " + request.getParameter("uname"));
The terminal prints:
Sesseion id: 9CEA218F32ACF766B339EDD174FEBB04
uid: 1205486576312
uname: 1205486576312
Sesseion id: FFBD081EF41AE538B7168943460F8DBF
uid: 1205486583578
uname: 1205486583578
But, in my application,
First, I need send a ajax request to the server, in order to get a validate code as a picture,
Then, when submit, I need to check the validate code at the server side. But the check process needs the same session id when the first used.
Is there anybody know how to fix it? I'm waiting...
the other item that can occur, if you clear cache and remove your cookies you could get a new session each time.
your server could have a timeout set real low - like zero but I have never seen this, but you should keep a valid session and this is not an ajax or extjs issue.
I use Ext in serveral selfwritten frameworks with sessions.
I had no problems using ajax.
Are you shure you aren't overwriting variables?
Ext.Ajax.request({
url: '/test/testLogin/',
success: function() {alert('success')},
failure: function() {alert('failure')},
params: { uid: new Date().getTime(), uname: new Date().getTime() }
});
Sincerely yours, ktp.
shjy.nicholas
03-14-2008, 02:26 PM
Hello everyone,
I really have no idea about this, i have tried server different ways.
In FF, i user firebug to see the details, the following information is showing in Firebug:
Response Headers
Server Apache-Coyote/1.1
Content-Type text/html
Transfer-Encoding chunked
Date Fri, 14 Mar 2008 10:19:02 GMT
Request Headers
Host localhost:8810
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12
Accept text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language zh-cn,zh;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset gb2312,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
X-Requested-With XMLHttpRequest
Content-Type application/x-www-form-urlencoded
Referer http://localhost:8810/test/testLogin.jsp
Content-Length 37
Cookie JSESSIONID=3905A277B7A137DA5E05F322294B50FE; seraph.os.cookie=LkFlIlGkCpDlLiEiMiOiKiGiHjGpNjDiFiMjHiFiNnPnCm
Pragma no-cache
Cache-Control no-cache
I remember that, I have test this program two months ago, but now, it does not works any more, and i can not find where the bug is.
shjy.nicholas
03-14-2008, 02:33 PM
I have write two simple Java Servlet to test the session id.
but the result is right, and the session is never re-new anymore.
That means, may be, the problem is the Ajax?
cerad
03-17-2008, 08:37 AM
Check what is being sent back to the server in the ajax request. The cookies should be in there. If not then you might have a domain or expiration problem.
redice
10-07-2008, 11:34 AM
Hi,
I encounter the same problem like shjy.nicholas said: use Ext.Ajax.request, web server always get a new session id.
the problem never happened in FF, but the problem always happened in IE6, or IE 7.
And another factor is on host name.
if FF, IE6, IE7 use ip address as url address, ex: http://192.168.0.12:8080/web, ajax request always send the same session id because browser keep the first set-Cookie value.
But IE6, IE7 use host name address, ex: http://abc_eu.bbb.net:8080/web, and the strange thing happened. server always get the different session id from every ajax request.
I found the different behavior on the set-Cookie http header.
IE6, IE7 didn't save session id in their cookies, maybe somebody will say: browser didn't allow to set cookie, but I did that all browser enable cookies.
I catch the http request/response message of IE7 when browser set session ind their cookie.
Although web server ask browser to set session in cookie by Set-Cookie:JSESSIONID=1c418adop85n1;Path=/webengine in the first response
but browser didn't save sessionid in cookie, so browser send the second request that don't have Cookie: JSESSIONID=1c418adop85n1
so web server can't accept JSESSIONID, and then create a new session id for non-sessionid request.
I don't know why FF, IE6, IE7 has different behavior on host name url address, if any idea or advice, I will be most appreciated. Please give me some direction to find the cause. thanks.
[first request]
Request Headers Value
(Request-Line) GET /webengine/ HTTP/1.1
Accept image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, application/x-shockwave-flash, */*
Accept-Language zh-tw,en-us;q=0.5
UA-CPU x86
Accept-Encoding gzip, deflate
User-Agent Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.1; .NET CLR 2.0.50727)
Host abc_eu.bbb.net:8080
Connection Keep-Alive
Response Headers Value
Transfer-Encoding:chunked
Set-Cookie:JSESSIONID=1c418adop85n1;Path=/webengine
Server:Jetty(6.1.11)
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Date:Tue, 07 Oct 2008 15:06:39 GMT
Content-Type:text/html; charset=utf-8
(Status-Line):HTTP/1.1 200 OK
////////////////////////////////////
[second request]
Request Headers Value
(Request-Line) GET /webengine/css/css_style.css HTTP/1.1
Accept */*
Referer http://abc_eu.bbb.net:8080/webengine/
Accept-Language zh-tw,en-us;q=0.5
UA-CPU x86
Accept-Encoding gzip, deflate
User-Agent Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.1; .NET CLR 2.0.50727)
Host abc_eu.bbb.net:8080
Connection Keep-Alive
Response Headers Value
Server Jetty(6.1.11)
Last-Modified Mon, 02 Jun 2008 08:49:26 GMT
Date Tue, 07 Oct 2008 15:06:40 GMT
Content-Type text/css
Content-Length 1710
(Status-Line) HTTP/1.1 200 OK
malek
12-23-2008, 06:44 AM
if FF, IE6, IE7 use ip address as url address, ex: http://192.168.0.12:8080/web, ajax request always send the same session id because browser keep the first set-Cookie value.
But IE6, IE7 use host name address, ex: http://abc_eu.bbb.net:8080/web, and the strange thing happened. server always get the different session id from every ajax request.
That exactely what happened !
I'm not using Ajax, but I had probleme only in IE7, and removing "_" from url resolved it
Thank you very much Redice !
Malek
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.