Struts文件上传
1. 页面配置:
<form action="upload.do" method="post" enctype="multipart/form-data">
标题:<input type="text" name="title"><br>
文件:<input type="file" name="file"><br>
<input type="submit" value="提交">
</form>
2. ActionForm中使用FormFile来接受上传文件,代码如下:
public class UploadForm extends
private FormFile file;
public FormFile getFile() {
return file;
}
public void setFile(FormFile file) {
this.file = file;
}
}
3. 在Action中使用FormFile来接收上传文件,代码如下:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ActionForward af = null;
UploadForm uploadForm = (UploadForm) form;// TODO Auto-generated method stub
FormFile myFile = uploadForm.getFile();
if(myFile!=null){
try {
FileOutputStream fos = new FileOutputStream("c://"+myFile.getFileName());
fos.write(myFile.getFileData());
fos.flush();
fos.close();
af = mapping.findForward("success");
} catch (Exception e) {
e.printStackTrace();
af = mapping.findForward("error");
}
}
return af;
}
4. 在struts-config.xml中的配置
配置form:
<form-bean name="uploadForm" type="com.zsw.struts.form.UploadForm" />
配置Action:
<action
attribute="uploadForm"
name="uploadForm"
path="/upload"
scope="request"
type="com.zsw.struts.action.UploadAction" >
<forward name="success" path="/upload_success.jsp" />
<forward name="error" path="/upload_error.jsp" />
</action>
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
生成验证码-超简单
轻松应对验证挑战:简单验证码的实现方法!
验证码 Java -
一个简单的struts实现文件上传示例
[code="java"]upload.jsp JSP for UploadForm form file : struts-c...
Struts Apache Myeclipse Java JSP -
Struts2的文件上传
基于Struts2的文件上传struts2文件上传
文件上传 struts -
【struts2】文件上传
Action类:package test;i...
struts java 上传 表单 复制文件 -
Struts2 简单的上传文件并且显示图片
代码结构: UploadAction.java index.jsp struts.jsp success.jsp
struts java html apache 上传 -
AIGC视频是什么格式
在上个月,佳能和索尼都发布了旗下的重磅全画幅微单相机,EOS R5和A7S3两款相机强悍的视频拍摄性能都让人留下了深刻印象。不过对于一些不太熟悉视频拍摄的用户来说可能会有些困惑,什么是RAW视频,什么又是log,ALL-I和IPB格式又有什么区别,不知道自己该如何设置,这里就为大家略微详细的解释一下视频的编码格式,并让大家能够大致了解RAW视频和log的区别。 佳能EOS R5支持8K
AIGC视频是什么格式 dbeaver 设置编码 jflash view log 访谈编码怎么做 存储容量 -
windows 编译brpc
Windows下编译FFmpeg-2.6.1详解 在诸多网友帮助下终于搞定了FFmpeg V2.6.1,由于编译环境和程序版本的不同,造成了很多不必要的时间浪费,特在此将编译过程和遇到的问题解决方法写出来,以便方便大家。
windows 编译brpc ffmpeg bc git Windows