Struts1_09_struts文件上传
来源:互联网 发布:免费开淘宝网店流程 编辑:程序博客网 时间:2024/06/09 17:44
一、web应用中的文件上传
1. commons-fileupload.jar apache组织的一个开源项目,性能稳定。
commons-io.jar
2. jspsmartupload.jar 使用简单。
3. 使用struts框架提供的文件上传功能:只是对commons-fileupload.jar的一个简单封装。
二、struts文件上传的步骤:
1. 页面的表单:
<form name="form1" action="xxx" method="post" enctype="multipart/form-data">
<input type="text" name="username"/><br/>
<input type="file" name="file"/>
</form>
注:表单中还可以有其它普通的输入域。
2. ActionForm中要有一个类型为org.apache.struts.upload.FormFile的字段,名字跟表单上的file域相同。
public FileUploadForm extends ActionForm{
prviate String username;
private FormFile file;
//getter & setter...
}
3.Action类中获取上传的文件:
public FileUploadAction extend Action{
public ActionForward execute(...){
FileUploadForm fuf = (FileUploadForm)form;
String username = fuf.getUserName();
FormFile ff = fuf.getFile();
InputStream is = ff.getInputStream();
...
}
}
4.在struts配置文件中用<controller>标记可以配置文件上传的一些参数设置。
三、struts多文件上传的解决方案:
在ActionForm定义对应个数量的FormFile属性来接收所有的文件数据。
1. commons-fileupload.jar apache组织的一个开源项目,性能稳定。
commons-io.jar
2. jspsmartupload.jar 使用简单。
3. 使用struts框架提供的文件上传功能:只是对commons-fileupload.jar的一个简单封装。
二、struts文件上传的步骤:
1. 页面的表单:
<form name="form1" action="xxx" method="post" enctype="multipart/form-data">
<input type="text" name="username"/><br/>
<input type="file" name="file"/>
</form>
注:表单中还可以有其它普通的输入域。
2. ActionForm中要有一个类型为org.apache.struts.upload.FormFile的字段,名字跟表单上的file域相同。
public FileUploadForm extends ActionForm{
prviate String username;
private FormFile file;
//getter & setter...
}
3.Action类中获取上传的文件:
public FileUploadAction extend Action{
public ActionForward execute(...){
FileUploadForm fuf = (FileUploadForm)form;
String username = fuf.getUserName();
FormFile ff = fuf.getFile();
InputStream is = ff.getInputStream();
...
}
}
4.在struts配置文件中用<controller>标记可以配置文件上传的一些参数设置。
三、struts多文件上传的解决方案:
在ActionForm定义对应个数量的FormFile属性来接收所有的文件数据。
- Struts1_09_struts文件上传
- 文件上传---文件上传
- 上传文件
- 文件上传
- 上传文件
- 文件上传
- 文件上传
- 上传文件
- 上传文件
- 文件上传
- 文件上传
- 文件上传
- 文件上传
- 文件上传
- 文件上传
- 文件上传
- 上传文件
- 文件上传
- Struts1_08_struts异常处理机制
- VC++内部COM插件的编程实现
- ogre+mfc+boost
- Android开发新手学习-inote记事工具
- 使用Flex,Java,Json更新postgresql数据
- Struts1_09_struts文件上传
- 显示Lion下的隐藏目录
- UITableView 在didSelectRowAtIndexPath 实现双击事件的方法
- 每个Java初学者都应该搞懂的六个问题
- AsyncTask的用法
- Struts1_10_Tiles框架
- Level Set需要掌握的知识:
- 使用cxf生成webservice客户端调用异常解决
- Android 应用程序之间数据共享—ContentResolver