Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with fileUpload

 
Pradyut Bhattacharya
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
i m using the commons file upload with jsp...(http://commons.apache.org/fileupload/)

My form is : -

I m able to retrieve the details using this code...

How do i use the "item" object in the else part(not a form field)

to point to a FileItem(org.apache.commons.fileupload.FileItem)

or particularly how do i use to store it to a database blob???

If i use another code for retrieving into FileItem i m getting exceptions........
DeferredFileOutputStream (probably at the line List /* FileItem */ items = upload.parseRequest(request);)

The code is

Thanks
Pradyut

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get an InputStream from it and save it in DB using PreparedStatement#setBinaryStream().

After all it look like that your problem is JDBC related rather than FileUpload related.

That said, is that code written in a JSP or a Servlet? To start, the code doesn't look good. Java code belongs in a Servlet and HTML belongs in a JSP.
 
Pradyut Bhattacharya
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.



when i do so(click edit buttton) the editor is filled with (&)lt and (&)gt..

original message should always be stored and any modification should be done on the presentation layer....

thats a bug for javaranch.... sorry there....
 
Pradyut Bhattacharya
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke Scholtz wrote:Get an InputStream from it and save it in DB using PreparedStatement#setBinaryStream().

After all it look like that your problem is JDBC related rather than FileUpload related.

That said, is that code written in a JSP or a Servlet? To start, the code doesn't look good. Java code belongs in a Servlet and HTML belongs in a JSP.


Yes i have done that......
Java code belongs in a Servlet and HTML belongs in a JSP.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradyut Bhattacharya wrote:
when i do so(click edit buttton) the editor is filled with (&)lt and (&)gt..

original message should always be stored and any modification should be done on the presentation layer....

thats a bug for javaranch....

That's not a bug, and it works fine. Perhaps you are not familiar with HTML entities. Have you tried editing your post to see what happens?
 
Pradyut Bhattacharya
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
Pradyut Bhattacharya wrote:
when i do so(click edit buttton) the editor is filled with (&)lt and (&)gt..

original message should always be stored and any modification should be done on the presentation layer....

thats a bug for javaranch....

That's not a bug, and it works fine. Perhaps you are not familiar with HTML entities. Have you tried editing your post to see what happens?


Yes i have changed it..
but still it was showing lt and gt and not < or >
that was what i was saying....
well may be nothing to worry for you guys....
 
Pradyut Bhattacharya
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke Scholtz wrote:Get an InputStream from it and save it in DB using PreparedStatement#setBinaryStream().

After all it look like that your problem is JDBC related rather than FileUpload related.

That said, is that code written in a JSP or a Servlet? To start, the code doesn't look good. Java code belongs in a Servlet and HTML belongs in a JSP.


but i do not get the file size...
using FileItem i could get that....
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Pradyut Bhattacharya
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Souther wrote:FileItem has both a getInputStream method and a getSize method.


but in my second code(where i use FileItemFactory) i m getting a DeferredFileOutputStream exception....

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic