• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Session in HTTPServlet

 
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?
 
Marshal
Posts: 67449
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67449
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
 
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
Marshal
Posts: 67449
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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

 
Good night. Drive safely. Here's a tiny ad for the road:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic