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


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Getting NullPointerException while uploading a file" Watch "Getting NullPointerException while uploading a file" New topic
Author

Getting NullPointerException while uploading a file

venu babu Karri
Greenhorn

Joined: Feb 18, 2010
Posts: 8
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
}

In Action we are saying

myForm.getMyFile().getFileName();

Here we are getting NullPointerException.


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: 39044
    
  23
Either myForm is null, or the getMyFile() method of myForm is returning null.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
venu babu Karri wrote: . . . Its urgent Please
There's no such thing as urgent here.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Moving to Struts.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
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

In action class please do the following

this will help
Apache fileupload
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

FormFile is a Strits 1 artifact.
venu babu Karri
Greenhorn

Joined: Feb 18, 2010
Posts: 8
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://aspose.com/file-tools
 
subject: Getting NullPointerException while uploading a file