• struts2多个文件上传


    struts2多个文件上传
    form表单:
    <form action="<%=basePath%>upload!moreupload.action"
    enctype="multipart/form-data" method="post">
    选择文件1<input type="file" name="file" /><br><br>
    选择文件2<input type="file" name="file" /><br><br>
    选择文件3<input type="file" name="file" /><br><br>
    选择文件4<input type="file" name="file" /> <br><br>
    <input type="submit" value="上传文件" />
    </form>

    action类:
    public String moreupload() throws IOException {
    String realpath = ServletActionContext.getServletContext().getRealPath(
    "/upload");  //获得文件目录
    if (file != null) {
    File savedir = new File(realpath);   //创建文件
    if (!savedir.exists())           //判断文件是否存在
    savedir.mkdirs();            //创建目录
    for (int i = 0; i < file.length; i++) {
    File savefile = new File(savedir, fileFileName[i]);   //依次把文件名保存起来
    FileUtils.copyFile(file[i], savefile);                //依次保存文件
    }
    ActionContext.getContext().put("message", "文件上传成功");
    return "success";
    }
    return "fail";
    }


    页面上:
    <body>
    ${message}
    </body>

    struts.xml配置略

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Nginx详解(正向代理、反向代理、负载均衡原理)
    java List的初始化
    nginx配置实现负载均衡
    SQL中where与having的区别
    数据库中where与having区别~~~
    group by的使用
    wm_concat函数
    Nginx配置upstream实现负载均衡1
    Nginx配置upstream实现负载均衡
    java
  • 原文地址:https://www.cnblogs.com/shipeng22022/p/4614072.html
Copyright © 2020-2023  润新知