Getting NullPointerException while uploading a file
venu babu Karri
Greenhorn
Joined: Feb 18, 2010
Posts: 8
posted
0
In my project,in the production some how we are getting NullPointerException while uploading a file. To upload a file we are using <html:file property=""> struts tag and we are using FormFile as the property of the form. We are trying to simulate this issue in the local by using Chrome,internet explorer,safari,Opera and mozila. we are unable to simulate, but in production we are getting NullPointerException while getting the form property like below
public class MyForm
{
private FormFile myFile;
setter & getter
}
if we don't upload any file, in action for the "myForm.getMyFile()" its giving empty. But some how in some cases we are getting for the same(myForm.getMyFile()) null. we are thinking that some browsers are not supporting file upload. Can you help me. Its urgent Please
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
4
posted
0
Either myForm is null, or the getMyFile() method of myForm is returning null.
No browser doesn't support file upload. (Although you should be checking for null--what if they *meant* to not upload a file? I don't recall what Struts 1 does under that circumstance.)
You need to figure out what's different between the requests that succeed and those that fail.
puneeth poduri
Greenhorn
Joined: Sep 16, 2010
Posts: 6
posted
0
hi venu babu Karri ,
if struts 2
do the following
in action tag in struts.xml make sure you do this
Then in your struts file tag please set the name attribute to myFile
Campbell Ritchie wrote:Either myForm is null, or the getMyFile() method of myForm is returning null.
getMyFile() is null. Then how it is becoming null.. I am unable to know. Generally while using <html:file> and FormFile to upload a file, If we dont upload a file getFormFile() gives empty string,If we upload some thing getFormFile() gives file name what we have uploaded. In some case getFormFile() is returning null.If you know.. Please let me know
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Getting NullPointerException while uploading a file