struts提供一种类型FormFile 这样就很方便我们做文件上传啦
首先在表单中 加一个属性 enctype="multipart/form-data"> 必须的 其他和以前一样
<html:form action="onLoadFile.do?op=onLoad" method="post" enctype="multipart/form-data">
<html:text property="name"></html:text><html:errors property="name"/>
<l
<html:file property="fileName"></html:file>
<html:submit>提交</html:submit>
</html:form>
在form中对应的属性值的类型是FormFile的类型
在action中
OnLoadFile onLoad = (OnLoadFile) form;
// 得到文件
FormFile file = onLoad.getFileName();
// 放在服务器的位置
String path = request.getSession().getServletContext().getRealPath(
"/images/" + file.getFileName());
// 声明文件写的流
FileOutputStream fos = new FileOutputStream(path);
//写文件
fos.write(file.getFileData());
fos.close();