日期:2014-05-18 浏览次数:20675 次
<body>
<form action="uploadAction.action" method="post" enctype="multipart/form-data">
<input type="file" name="image"><br/>
<input type="submit" value="上传">
</form>
${message}
</body>
public class UploadAction extends ActionSupport {
private File image;
private String imageFileName;
private String imageContentType;
private String filePath;
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public File getImage() {
return image;
}
public void setImage(File image) {
this.image = image;
}
public String getImageFileName() {
return imageFileName;
}
public void setImageFileName(String imageFileName) {
this.imageFileName = imageFileName;
}
public String getImageContentType() {
return imageContentType;
}
public void setImageContentType(String imageContentType) {
this.imageContentType = imageContentType;
}
@Override
public String execute() throws Exception {
System.out.println("upload");
String realpath = ServletActionContext.getServletContext().getRealPath(
"/images");
if (this.image != null) {
File savefile = new File(new File(realpath), imageFileName);