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

Session in HTTPServlet

Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Hi,

I have a servlet that extends HTTPServlet and implements servlet. In the doPost I handle upload with apache commons upload



When trying to access the FILE-UPLOAD-LISTENER in doGet that is called from AJAX I sometimes get null.



The listener is sometimes null. How is this possible and how can I get around this? Any pointers?


SCJP1.4
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60994
    
  65

How are you going about initiating a multi-part form request using Ajax?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
I'm not

I have a form that has an action to the servlet.
in the onSubmit() I call my start() function for ajax. And there I call the Servlet by GET.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60994
    
  65

That's not going to work. You can't submit a multi-part form using Ajax.

(Libraries like jQuery with its Forms plugin appear to let you -- but they;re really submitting the form normally in an iframe and not using XMLHttpRequest.)
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
I think you missunderstand me mainly because of my bad english i suppose.

This is what I do.

Javaworld article about progress bar

It is not an AJAX request with multipart since this doesn't work. I make a post to an IFrame and then start an asyncron AJAX GET to my servlet that uses apache commons upload. My problem is that the session is not always set.

// Mathias
Sekyi Zulu
Greenhorn

Joined: May 24, 2009
Posts: 3
Mathias Nilsson wrote:I think you missunderstand me mainly because of my bad english i suppose.

This is what I do.

Javaworld article about progress bar

It is not an AJAX request with multipart since this doesn't work. I make a post to an IFrame and then start an asyncron AJAX GET to my servlet that uses apache commons upload. My problem is that the session is not always set.

// Mathias


I think the issue is you're expecting HttpSession session to behave similar to AJAX (WebContext) session handlers...HttpSession is managed by the container. WebContextFactory will return a WebContext object you can use to retrieve the session sent via XMLHttp...You'll need to decide on one type of session object...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60994
    
  65

Sekyi Zulu wrote:WebContextFactory will return a WebContext object ...

These are DWR classes. I see nowhere where the OP states he is using DWR.

And, Ajax request will participate in the normal servlet container session handling.

More info on how you are initiating the request will be needed.
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Ok

Here is my servlet and ProgressListener




Here is my html and javascript

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session in HTTPServlet