Reputation: 772
I need to upload files and save them in specific locations based on their names. I am using the following code but not sure how to save them based on their names. Currently it gives me the following error.
SEVERE: Exception occurred during processing request: null
java.lang.NullPointerException
Jsp
<s:form method="POST" enctype="multipart/form-data" autocomplete="on"
action="myforms">
.......
<s:textfield name="Name" label="Name"/>
<s:file name="logo" label="Upload Logo" size="40"/>
<s:submit validate="true"></s:submit>
Action
@Action
public class MyFormHandler implements ModelDriven{
private FormData formData;
private File logo;
public String myforms(){
System.out.println(formData.getName()); // << it works
System.out.println("file name:" + logo.getName()); << Error
}
public File getLogo() {
return logo;
}
public void setLogo(File logo) {
this.logo = logo;
}
......
}
Upvotes: 0
Views: 242
Reputation: 160301
The code you show makes no sense on its own; the uploaded file will be in File logo
(assuming proper getters/setters etc.) and I have no clue what FormData
is.
Your best bet is to copy the uploaded file to whatever directory you want based on its name, but without further info it won't be easy to ascertain what's going wrong in your case.
Upvotes: 1