要注意的几点:
1.jsp页面。
1.1提交的form要写enctype="multipart/form-data",
<html:form action="/gamearticlesae?method=addnew" enctype="multipart/form-data">
</html:form>
1.2jsp页面用JS动态添加控件的方法:
js 代码
- <script>
- var idIndex=0;
- function addFile()
- {
- oTR=idTB.insertRow(idTB.rows.length);
- tmpNum=oTR.rowIndex;
- oTD=oTR.insertCell(0);
- oTD.innerText = tmpNum;
- alert(tmpNum);
- oTD.innerHTML ="<input type='file' name='file("< span="">+tmpNum+")'> <button onclick='removefile();'>delete
";
- idLast.innerText=idTB.rows.length;
- if(idTB.rows.length>0)
- idFirst.innerText='1';
- return true;
- }
- function removeFile()
- {
- sIndex=idIndex.value;
- if(sIndex=='')
- sIndex=idTB.rows.length-1;
- else
- sIndex=parseInt(sIndex)-1;
-
- idTB.deleteRow(sIndex);
-
- idLast.innerText=idTB.rows.length;
- if(idTB.rows.length==0)
- idFirst.innerText='0';
- }
- </script>
相应的:
js 代码
- "addFile()" value="添加附件">
-
-
2.actionform的问题
因为附件的个数是不确定的,所以用
java 代码
- private List files = new ArrayList();
-
- public FormFile getFile(String index) {
- return (FormFile) files.get(Integer.parseInt(index));
- }
-
- public void setFile(String index, FormFile file) {
- this.files.add(file);
- }
-
- public List getFiles() {
- return this.files;
- }
-
3.action
java 代码
- Hashtable fileh=gamearticlesaeForm.getMultipartRequestHandler().getFileElements();
- for (Enumeration e = fileh.keys(); e.hasMoreElements(); ) {
- String key = (String) e.nextElement();
- try {
- FormFile formfile = (FormFile) fileh.get(key);
- String filename = formfile.getFileName().trim();
- log.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ the filename is "+filename);
- }
- catch(Exception sse){}
- }
翻了下孙MM的书,
java 代码
<html:file property="xxx">
</html:file>
这样就OK了
分享到:
相关推荐
java基于struts框架写的多附件上传;包含action类与jsp页面的配置信息
struts2 实现多文件上传功能,是一个很好的学习参考资料
strtus技术架构实现附件上传,风格参照163网址的样式
Struts2多个文件上传 多个文件上传分为List集合和数组,下面我们着重介绍一下list集合的上传。都大同小异。
Struts1.2动态FormBean 加 验证功能 的一个例子
ajaxFileUpload+struts2实现多文件上传(动态添加文件上传框)(项目源码) 博文地址:http://blog.csdn.net/itmyhome1990/article/details/36433621
struts实现的文件上传下载功能,最大可以上传到150MB
用Struts框架实现单文件上传功能(初学者的入门项目案例),本项目适合课后作业的哦.
struts上传struts上传 struts上传struts上传
1.能够对多个文件进行上传(可以选择上传文件个数,也即上传文件个数不定) 2.能够对上传路径进行配置文件指定(upload.properties),使用了一些类似单例模式的静态代码块 3.Struts2进行下载处理,能对上传的所有...
struts2实现文件上传(单个+多个文件上传
struts1.2实现动态多文件上传,可实现代码全奉献!
struts1和struts2分别实现文件上传下载功能
struts2一个action处理多个请求
struts2实现的多个文件上传struts2实现的多个文件上传struts2实现的多个文件上传struts2实现的多个文件上传
struts1.2开发,可实习自定义,任意多个文件上传
struts1单个上传和多个上传,一个工程,两张上传方式
动态上传附件到服务器目录下,主要通过流的读书写,runtime 建立文件目录
实现struts同时上传多个文件!
struts1上传多个文件 jquery multi什么的组件