strut 多文件上传

简介: jquery动态添加动态的添加文件上传框以及动态的删除上传框<script type="text/javascript">$(function()        {            $("#button").click(function()            {                var html = $("<input type='file

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

目录
相关文章
|
30天前
使用ueditor实现多图片上传案例——DaoImpl层(ShoppingDaoImpl)
使用ueditor实现多图片上传案例——DaoImpl层(ShoppingDaoImpl)
13 0
|
30天前
使用ueditor实现多图片上传案例——Servlet层(UploadServlet)
使用ueditor实现多图片上传案例——Servlet层(UploadServlet)
6 0
|
30天前
使用ueditor实现多图片上传案例——DaoImpl层(BaseDaoUtilImpl)
使用ueditor实现多图片上传案例——DaoImpl层(BaseDaoUtilImpl)
10 0
|
4月前
|
Java Spring
SpringMVC多文件上传
SpringMVC多文件上传
35 0
|
6月前
|
开发框架 JavaScript 前端开发
11dwr - dwr.xml配置(allow标签-Creator属性)
11dwr - dwr.xml配置(allow标签-Creator属性)
24 0
|
NoSQL
OkhttpUtils单、多文件上传
OkhttpUtils单文件上传
512 0
|
前端开发 Java 网络架构
SpringMVC的form表单标签使用(八)上
SpringMVC的form表单标签使用(八)
234 0
SpringMVC的form表单标签使用(八)上
|
存储 前端开发 数据库
SpringMVC的form表单标签使用(八)中
SpringMVC的form表单标签使用(八)
233 0
SpringMVC的form表单标签使用(八)中
|
存储 前端开发 数据处理
SpringMVC的form表单标签使用(八)下
SpringMVC的form表单标签使用(八)
286 0
SpringMVC的form表单标签使用(八)下
|
网络安全 Java
SSH框架整合——strut2完成forword跳转
strut2固定是request的请求重定向方式进行跳转 如果界面中用forword来完成跳转: 会报请求错误的异常,所以需要在web.xml中修改strut2的配置 struts2 /* FORWORD REQUEST 这样既可以接收request请求,又...
1160 0