struts本身对文件上传进行了支持.
在struts-config.xml中进行配置
<
form-bean
name
="upFileForm"
type
="org.apache.struts.action.DynaActionForm"
>
< form-property name ="upFile" type ="org.apache.struts.upload.FormFile" />
</ form-bean >
< form-property name ="upFile" type ="org.apache.struts.upload.FormFile" />
</ form-bean >
在JSP中要指定上是multipart/form-data
<
html:form
action
="/up"
method
="post"
enctype
="multipart/form-data"
>
< html:file property ="upFile" />< html:submit />
</ html:form >
< html:file property ="upFile" />< html:submit />
</ html:form >
在action对上传文件处理
DynaActionFormupFileForm
=
(DynaActionForm)form;
FormFileupFile = (FormFile)upFileForm.get( " upFile " );
try ... {
response.getWriter().write(upFile.getFileName());
} catch (IOExceptione) ... {
e.printStackTrace();
}
FormFileupFile = (FormFile)upFileForm.get( " upFile " );
try ... {
response.getWriter().write(upFile.getFileName());
} catch (IOExceptione) ... {
e.printStackTrace();
}