Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session in HTTPServlet

 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you going about initiating a multi-part form request using Ajax?
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok

Here is my servlet and ProgressListener




Here is my html and javascript

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic