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";
    }

  • 相关阅读:
    mysql高可用架构的构想
    shell进阶——expect免交互工具的使用
    Mysql性能优化之参数配置(转)
    mysql主从同步问题梳理
    使用mysql-proxy实现mysql的读写分离
    Mysql数据库的主从与主主
    Mariadb远程登陆配置及相关问题排查
    redis集群搭建及常用操作
    weblogic的linux静默搭建
    Python traceback 模块,追踪错误
  • 原文地址:https://www.cnblogs.com/aiwoqu/p/4146268.html
Copyright © 2011-2022 走看看