zoukankan      html  css  js  c++  java
  • struts2单个文件上传

    struts2单个文件上传


    form表单:
    <form action="<%=basePath%>upload!upload.action"
    enctype="multipart/form-data" method="post">
    选择文件<input type="file" name="file" /> <input type="submit"
    value="上传文件" />
    </form>

    action类:
    private File file;
    private String fileFileName;
    private String uploadfileContentType;

    public String upload() throws IOException {
    String realpath = ServletActionContext.getServletContext().getRealPath(
    "/upload");    //获得路径
    if (file != null) {
    File savefile = new File(new File(realpath), fileFileName);//获得文件地址
    if (!savefile.getParentFile().exists())     //判断文件是否存在
    savefile.getParentFile().mkdirs();      //创建目录
    FileUtils.copyFile(file, savefile);          //保存文件
    ActionContext.getContext().put("message", "文件上传成功");  把message信息传送到页面上
    return "success";
    }
    return "fail";
    }

    接收信息页面上:
    <body>
    ${message}
    </body>

    struts.xml配置略

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

  • 相关阅读:
    timeDate.js 插件优化
    向页面中插入不同格式的时间(timeDate.js)
    html
    html
    html
    html
    three.js
    three.js
    three.js
    python之路_头像预览、each循环及form组件校验验证码
  • 原文地址:https://www.cnblogs.com/shipeng22022/p/4614073.html
Copyright © 2011-2022 走看看