File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes problem with fileUpload  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "problem with fileUpload  " Watch "problem with fileUpload  " New topic
Author

problem with fileUpload

Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63
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


Pradyut
http://pradyut.tk/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61300
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Aug 12, 2004
Posts: 63
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

Joined: Aug 12, 2004
Posts: 63
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
Marshal

Joined: Mar 22, 2005
Posts: 42030
    
  64
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?


Ping & DNS - my free Android networking tools app
Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63
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

Joined: Aug 12, 2004
Posts: 63
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

Joined: Dec 11, 2004
Posts: 13410

FileItem has both a getInputStream method and a getSize method.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63
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....

 
GeeCON Prague 2014
 
subject: problem with fileUpload