zoukankan      html  css  js  c++  java
  • Struts2框架下的文件上传文件类型、名称约定

    Struts2框架下的文件上传机制:
    1.通过multipart/form-data form提交文件到服务器
    2.文件名是通过什么地方设置的?
    在strust2的FileUploadInterceptor中
    有下面这段代码,将参数写入写入到request的parameters中,再通过OGNL注入到Action中去。
    所以按照struts2约定,上传文件名以及上传文件类型和上传文件本身,都是以页面input的name来决定的。
    String[] fileName = multiWrapper.getFileNames(inputName);//得到请求的所有文件名

    if (isNonEmpty(fileName)) {
    // get a File object for the uploaded File
    File[] files = multiWrapper.getFiles(inputName);
    if (files != null && files.length > 0) {
    List<File> acceptedFiles = new ArrayList<File>(files.length);
    List<String> acceptedContentTypes = new ArrayList<String>(files.length);
    List<String> acceptedFileNames = new ArrayList<String>(files.length);
    String contentTypeName = inputName + "ContentType";//默认就是input名称+ContentType
    String fileNameName = inputName + "FileName";//默认就是input名称+FileName

    for (int index = 0; index < files.length; index++) {
    if (acceptFile(action, files[index], fileName[index], contentType[index], inputName, validation, ac.getLocale())) {
    acceptedFiles.add(files[index]);
    acceptedContentTypes.add(contentType[index]);
    acceptedFileNames.add(fileName[index]);
    }
    }

    if (!acceptedFiles.isEmpty()) {
    Map<String, Object> params = ac.getParameters();//添加到parameters中 这样就可以通过OGNL注入到action了

    params.put(inputName, acceptedFiles.toArray(new File[acceptedFiles.size()]));
    params.put(contentTypeName, acceptedContentTypes.toArray(new String[acceptedContentTypes.size()]));
    params.put(fileNameName, acceptedFileNames.toArray(new String[acceptedFileNames.size()]));
    }
    }

  • 相关阅读:
    均匀分布
    吉布斯采样(Gibbs采样)
    蒙特卡罗方法 Monte Carlo method
    马尔科夫链
    python 3 没有了xrange
    %matplotlib inline的含义
    MCMC采样和M-H采样
    pycharm 安装模块 use the correct version of 'pip' installed for your Python interpreter
    Pycharm安装第三方库时出现Read timed out的解决办法
    如何在Pycharm中添加新的模块(第三方包)
  • 原文地址:https://www.cnblogs.com/justbeginning/p/3679185.html
Copyright © 2011-2022 走看看