This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Session in HTTPServlet

 
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok

Here is my servlet and ProgressListener




Here is my html and javascript

 
reply
    Bookmark Topic Watch Topic
  • New Topic