Sangram Anand
Sangram Anand

Reputation: 10844

Get file name when uploading file using ajax in Struts2

I am trying fileupload using ajax in a struts2 framework webapp. I am using the "fileupload" interceptor in the action mapping, i am getting the file content in the action, but not the uploaded fileName i.e.,

private File file; // + its setters & getters methods.
private String fileName; // + its setter & getters methods.

System.Out.println(file.getName()); //prints some .tmp file 

The fileName variable is null.

Do i have to specify any file Details while making an ajax call to get the FileName of the uploaded file ?

-- Thanks

Upvotes: 0

Views: 1033

Answers (2)

Gopal
Gopal

Reputation: 1340

It should be like this

if the "name" attribute of the on your page is "xxx"

private File xxx;
private String xxxContentType;
private String xxxFileName;

Upvotes: 1

MohanaRao SV
MohanaRao SV

Reputation: 1125

FileUpload Interceptor

You should provide setter method appropriately. Follow naming convention carefully. Refer above link

Struts2 FileUpload Example

Upvotes: 0

Related Questions