structs中文件上传
文件上传jsp界面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<html:form action="upload" method="post" enctype="multipart/form-data">
文件:<html:file property="file" />
<html:submit value="上传" property="submit"/>
</html:form>
</body>
</html>
form封装文件
package com.inspur.form;
import java.util.Date;
import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;
public class FileForm extends ActionForm {
/**
* @xinshaxin
*/
private static final long serialVersionUID = 1L;
// 文件名
private String fileName;
//文件大小
private int fileSize;
//文件表单封装
private FormFile file;
public FormFile getFile() {
return file;
}
public void setFile(FormFile file) {
this.file = file;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public int getFileSize() {
return fileSize;
}
public void setFileSize(int fileSize) {
this.fileSize = fileSize;
}
}
事件
package com.inspur.form;
import java.util.Date;
import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;
public class FileForm extends ActionForm {
/**
* @xinshaxin
*/
private static final long serialVersionUID = 1L;
// 文件名
private String fileName;
//文件大小
private int fileSize;
//文件表单封装
private FormFile file;
public FormFile getFile() {
return file;
}
public void setFile(FormFile file) {
this.file = file;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public int getFileSize() {
return fileSize;
}
public void setFileSize(int fileSize) {
this.fileSize = fileSize;
}
}