It's hard to tell, but it looks like you've created a custom class named FormFile, and the code for that object is displayed above under the heading "object class". Is that right?
If so, this is what is causing the problem. When doing a file upload, the ActionForm property associated with the file to be uploaded must be of type org.apache.struts.upload.FormFile. It can't be a custom class.
Struts will populate this object for you when the form is submitted. In your Action class, you can then use the FormFile's getInputStream() method to get an input stream for the file being uploaded. Once you have the input stream, you can then use it to write to another object such as a file or a Blob.
This link shows an example of both a file upload to a Blob and a file download from a Blob.
im having the following error using the codings displayed below: java.lang.NullPointerException com.strutsexample.action.ContentAction.insert(ContentAction.java:51) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:585)
This is my object class
this is my formbean class:
my struts action class:
Joined: Feb 15, 2005
The Stack trace tells you that a NullPointerException is occuring at line 51 of your ContentAction class. Find which object is being dereferenced at line 51. That's the object that is null when you aren't expecting it to be. Then find out why it's null.
Joined: Oct 15, 2006
this is the line: content.setFile(Hibernate.createBlob (myFile.getInputStream()));
Joined: Feb 15, 2005
myFile must be null. Find out why.
Here's one thing you may want to check: If the size of the file is greater than what you specified in your struts-config.xml file in <controller maxFileSize="" /> Struts will not upload the file and the property in your ActionForm will be null. [ March 12, 2007: Message edited by: Merrill Higginson ]