views:

1586

answers:

3

I am using SWFUpload to upload files to java servlet (spring framework). The problem is that the current web session is lost during file upload (it creates a new session). I read that it is a known bug and there are some workarounds somewhere but I can't find anything. Does anyone know how to make it work?

Thanks.

A: 

Had this on the .NET platform as well. The problem is that the Flash Object runs in a different session context than your Java App (it's effectively treated like a new client). One way to get around all of this is to effectively have the object post any necessary information needed to commit the uploads back in the querystring.

Nissan Fan
+3  A: 

Have a look at this post on the SWFUpload forums. Adding ;jsessionid=XXX to the upload URL may work for you, or it may not; the exact cause of the problem appears unclear. Note that Flash uses the Wininet stack (same as IE), so if you are using a different browser you need to somehow get the session cookie (known to your browser) into the IE cookie.

Vinay Sajip
This is certainly a potential solution if your web server supports it (most Java Containers do allow session id in the querystring).
Nissan Fan
It doesn't work for me...
serg
What doesn't work, exactly? Note that my suggestion uses a semicolon rather than ? to add the session data - did you use this? What does your URL look like?
Vinay Sajip
Actually it works in IE (even without jsession) but not in FF. You said: somehow get the session cookie (known to your browser) into the IE cookie. How would I do that?
serg
By adding `;jsessionid=XXX` to the URL :-)
Vinay Sajip
I tried that but it doesn't help. I also tried to pass all cookies through SWFUpload.post_params but it still doesn't work.
serg
Can I somehow get session by id in java? Lets say I just pass sessionid as a regular parameter, can I access this session by id? There used to be HttpSessionContext but it is deprecated now without a replacement.
serg
Can you show the actual URL which is being passed (and which includes the `;jsessionid=XXX`?
Vinay Sajip
/fileUpload.html;jsessionid=8EB0F94EB5E5C17FECD3787743B2ED20
serg
So, I assume fileUpload.html maps to a servlet, right? What do you see in the servlet which is handling the POST request when you try to get the session?
Vinay Sajip
Right. What exactly are you interested in? I see there new sessionid. org.springframework.web.multipart.MultipartHttpServletRequest is what my request is. Request params contain "upload" and "filename" attributes from sfwupload.
serg
I'm thinking about the request headers, particularly the *Cookie* header. Presumably there is a session cookie in the request headers which is being used to map to the "other" session. You may have to resort to removing this cookie somehow so that there's only one session ID. Also worth confirning that the session cookie name actually _is_ `jsessionid`. What servlet container are you using?
Vinay Sajip
If session cookie was there I wouldn't have any problems in the first place I think. Session name is JSESSIONID (I tried it as well).
serg
I'm not sure what servlet container you're using, so I'm not sure where it looks for a session ID. Normally it would be either in the URL or in a cookie; if you are supplying it in the URL, either it's getting a different value from a cookie and using that, or it's configured to ignore session IDs passed in the URL. Seems somewhat container-specific at the moment.
Vinay Sajip
A: 

Vinay Sajip's answer hv all to be right, but doesnt work with me.

thats what i've done :

1 - Set my servlet (in this case, doPost) to synchronized.

protected synchronized void doPost(HttpServletRequest request, HttpServletResponse response)

2 - in upload_url from swfupload, i passed through the session ID

upload_url: "Controller?action=33&JSESSIONID=<%=request.getSession().getId()%>",

3 - back to the servlet, i forced the cookie JSESSIONID to my "old" session:

if (request.getParameter("JSESSIONID")!=null) { Cookie userCookie = new Cookie("JSESSIONID", request.getParameter("JSESSIONID")); response.addCookie(userCookie); }

should work. i've used synchronized because to not have a "duplicate" value of sessionId. (or my firebug is crazy)

Fusion