aspose file tools*
The moose likes Servlets and the fly likes Session IDs are different from GET and POST method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session IDs are different from GET and POST method" Watch "Session IDs are different from GET and POST method" New topic
Author

Session IDs are different from GET and POST method

Colin Zheng
Greenhorn

Joined: Oct 25, 2011
Posts: 15
Here is what I am trying to do:
Upload a file from a form with POST method and get the progress status with GET method. And I put a progresslistener variable in the session to feedback the upload progress to the AJAX in the frontend. For some reason, in the doGet and doPost methods in the servlet, the session.toString() returns different IDs. Shouldn't they be the same if the requests are from the same browser?

Thanks,
Colin
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Ignore the results of toString(), it's not specified what that format may be. I don't know what you mean by ID, but that could be the hexadecimal hash code of the actual object. You should use getId() instead, which returns the actual session ID. That should be the same.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Colin Zheng
Greenhorn

Joined: Oct 25, 2011
Posts: 15
Thanks Rob.
I changed to session.getId() and it's the same. I still got 2 different IDs.
Then I moved the code from doGet() to doPost() and there is a ServletFileUpload.isMultipartContent(request) to judge if the request is file uploading or getting progress. Still, I got 2 different IDs.
Note that most of the time, I got sames IDs. Just occasionally, 2 different IDs occurred.
Can somebody help please?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Why is that a problem? I haven't ever had to use the session ID when uploading a file.
Colin Zheng
Greenhorn

Joined: Oct 25, 2011
Posts: 15
Because I store a progress listener in the session to uniquely identify the clients...

thanks,
Colin
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

And you are getting different sessions? Your focus on the session ID kind of led us away from the actual question, which I guess was why were you getting different sessions. Perhaps your AJAX code is not handling cookies correctly.
Colin Zheng
Greenhorn

Joined: Oct 25, 2011
Posts: 15
Here are some details about my issue. If the request is a file uploading, get/create a session. If the request is for a progress update, get the session. The problem is sometimes it can never get the session which has been created in the 'file uploading' code. I can't figure out why.
Here is the code:




Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I don't understand any of that. (The while-loop is especially incomprehensible.) You're trying to use a separate session for each upload? Why?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session IDs are different from GET and POST method