使用Struts 2框架上传文件(4)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-06 18:18 点击:次
this.attachmentContentType = attachmentContentType;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
public String execute() throws Exception
{
if (attachment != null)
{
String dataDir = "d:\\images";// 上传文件存放的目录
File savedFile = new File(dataDir, attachmentFileName);// 上传文件在服务器具体的位置
attachment.renameTo(savedFile);// 将上传文件从临时文件复制到指定文件
}
else
{
return INPUT;
}
return SUCCESS;
}
}
上传文件的表单:
<s:form action="single_upload" method="post" enctype="multipart/form-data"> <s:textfield name="description" label="description"></s:textfield> <s:file name="attachment" label="Choose a File to Upload"></s:file> <s:submit value="submit"></s:submit
相关新闻>>
- 发表评论
-
- 最新评论 更多>>