jquery动态添加动态的添加文件上传框以及动态的删除上传框
<script type="text/javascript"> $(function() { $("#button").click(function() { var html = $("<input type='file' name='upload'>"); var button = $("<input type='button' name='button' value='删除'><br>"); $("#div").append(html).append(button); button.click(function() { html.remove(); button.remove(); }) }) }) </script> <form action ="${ctx}/order/upload.action" method="post" enctype="multipart/form-data"> <input name="upload" type="file"> <input type="button" value="添加" id="button"><br> <div id="div"></div> <button>提交</button> </form>
后台代码:
private List<File> upload;
private List<String> uploadContentType;
private List<String> uploadFileName;
public String upload(){
//服务端存放上传文件目录
String destPath = ServletActionContext.getServletContext().getRealPath("/upload");
System.out.println(destPath);
File file=new File(destPath);
if(!file.exists()) file.mkdirs();
System.out.println(file);
try {
for (int i=0;i<upload.size();i++)
{
FileUtils.copyFile(upload.get(0), new File(file,uploadFileName.get(i)));
}
} catch (IOException e) {
e.printStackTrace();
return ERROR;
}
return SUCCESS;
}
appendChild是DOM对象的方法
append是Jquery对象的方法
参考文章:
http://www.cnblogs.com/xiaoluo501395377/archive/2012/10/26/2740882.html
strut 2单文件上传:
http://tianxingzhe.blog.51cto.com/3390077/1681576
本文出自 “点滴积累” 博客,请务必保留此出处http://tianxingzhe.blog.51cto.com/3390077/1681604