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
>
在JSP中要指定上是multipart/form-data
<
html:form
action
="/up"
method
="post"
enctype
="multipart/form-data"
>
<
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();
}
本文介绍如何使用Struts框架配置文件上传功能。主要内容包括在struts-config.xml中定义上传表单bean,设置JSP页面的编码类型为multipart/form-data,并在Action中处理上传的文件。

548

被折叠的 条评论
为什么被折叠?



