zoukankan      html  css  js  c++  java
  • 上传文件HTML前台

    <form name="form1" encType="multipart/form-data" method="post">
    <!-- <input type="file" id="inputfile" name="upload"
    accept="text/plain" > -->
    <input id="inputfile" type="file" style="display:none" name="file" accept=".xls,.doc,.txt,.pdf,xlsx" >
    <div style="float: left; padding-left: 15px" >
    <input id="photoCover" class="form-control" type="text" style="height:34px;">
    </div>
    <div style="float: left; padding-left: 5px" >
    <a class="btn btn-info" onclick="$('input[id=inputfile]').click();">导入单个员工信息</a>
    </div>
    <div style="float: left; padding-left: 5px" >
    <button id="uploadBtn" class="btn btn-info">导入提交</button>
    </div>
    </form>

    $('input[id=inputfile]').change(function() {
    $('#photoCover').val($(this).val());
    });

    新建Action 

    public class UploadAction extends ActionSupport{

    private File image; //上传的文件
    private String imageFileName; //文件名称
    private String imageContentType; //文件类型

    get........set..........


    public String execute() throws Exception {
    String realpath = ServletActionContext.getServletContext().getRealPath("/images");
    //D:apache-tomcat-6.0.18webappsstruts2_uploadimages
    System.out.println("realpath: "+realpath);
    if (image != null) {
    File savefile = new File(new File(realpath), imageFileName);
    if (!savefile.getParentFile().exists())
    savefile.getParentFile().mkdirs();
    FileUtils.copyFile(image, savefile);
    ActionContext.getContext().put("message", "文件上传成功");
    }
    return "success";
    }

  • 相关阅读:
    PHP深入浅出之命名空间(Namespace)的使用详解
    函数func_get_args详解
    验证码封装类
    PHP中SESSION自定义会话管理器
    网页开发常见问题总结
    mysql远程连接只显示部分数据库问题
    认识和学习bash
    IPv6地址格式示例及IPv6与IPv4的区别分析
    用HTTP核心模块配置一个静态Web服务器
    Nginx服务项的基本配置
  • 原文地址:https://www.cnblogs.com/aiwoqu/p/4146268.html
Copyright © 2011-2022 走看看