Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

upload data and image at the same time

 
jhon masco
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I need to send data from a form to a database but... this form have a field input also. I trying to send all the data together (image and input text values) but I can't.
Is to say in the database I just get the image but not the input text values! I read in someplace that is not possible but...I had seen that working fine in some websites!
What is wrong?
Here the code that I am -testing:
1)the jsp form:


2) and the uploadimage servlet


NOTE: the 2 values showed with System.out.print are null.

Please give me an idea.

THANKS
 
Stefan Evans
Bartender
Posts: 1712
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Much as you may hate it, my suggestion would be to throw away half of this code, and use a library to parse the response for you.

The commons fileupload component is a commonly used one.
That library enables you to read both the uploaded file and the parameters sent along with it.

 
jhon masco
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:Much as you may hate it, my suggestion would be to throw away half of this code, and use a library to parse the response for you.

The commons fileupload component is a commonly used one.
That library enables you to read both the uploaded file and the parameters sent along with it.



Thanks Stefan
I will read about Jakarta FileUpload. Already I had seen it before but I never thinked that I would be diffcult submit values an images at the same time.
I will try these examples: example1 and example2
I hate when the examples just show how submit images and not data too!!!
If anyone know other alternative please let me know.
Gracias
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can read the other form parameters like this



Again, if you are just trying out, or if you have choice to use tomcat 7 (if you are starting a new project or just learning servlets),
Try out the @MultipartConfig and built in file upload support in servlet 3.0 Spec.
It has made life really easier, you will not need any additional library like commons file upload or any other multipart parser.
 
jhon masco
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sudhir nim wrote:Again, if you are just trying out, or if you have choice to use tomcat 7 (if you are starting a new project or just learning servlets),
Try out the @MultipartConfig and built in file upload support in servlet 3.0 Spec.
It has made life really easier, you will not need any additional library like commons file upload or any other multipart parser.


Thanks Sudhir
Nice tips specially @MultipartConfig. I will continue trying fileupload library while I change to tomcat 7.
Also I had found other good tips here if anyone need help must check the link.

Thank you very much.
 
jhon masco
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again
Here the solution using jakarta fileupload library

Luck! and thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic