This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Uploading Image To the server  RSS feed

 
Rajat Raina
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to upload an image from the jsp page. I want to store the same image with three names. For the first time the image is stored but it gives a NullPointer Exception at FileItem write method second time in the loop.
Please help.....
Code is

There is a NullPointerException at line 13 second time in the loop
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly is null?
What is the trace?

Edit: your code at its own makes less sense. You're doing it three times for all the files. Once the stream is already read, you can't read it again. Remove that for-loop and that session getting/setting. Just keep it simple and follow the user guide at commons fileupload homepage. Once you're finished with that all, you're free to duplicate the files using the usual java.io stuff.
 
Rajat Raina
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bauke
It worked the way you told but I still have a doubt. The request stored in the List can be saved as an attribute of session so that the List can be used mutiple times.I am a bit confused on this. That is way i have used that that session getting/setting.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is still inside the same code block. You can just access the same reference.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!