我需要上传文件并根据它们的名称将它们保存在特定位置。我正在使用以下代码,但不确定如何根据它们的名称保存它们。目前它给了我以下错误。
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
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;
}
......
}