zoukankan      html  css  js  c++  java
  • Struts2文件上传

    平时都是直接在action中按照struts2定义的格式来接流,最近看到华为技术人员调用struts2底层方法对文件流做了封装,感觉有用赶紧记了下来 

    Java代码  
     
     
     
    public void preExecute()  
        {  
            if (httpServletRequest instanceof MultiPartRequestWrapper)  
            {  
                MultiPartRequestWrapper requestWrapper = (MultiPartRequestWrapper) httpServletRequest;  
                Enumeration<String> parameterNames = requestWrapper.getFileParameterNames();  
                while (parameterNames.hasMoreElements())  
                {  
                    @SuppressWarnings("unused")  
                    String paramterName = parameterNames.nextElement();  
                    File[] files = requestWrapper.getFiles(paramterName);  
                    if (null == files || files.length == 0)  
                    {  
                        continue;  
                    }  
                    else if (files.length == 1)  
                    {  
                        FileBean fileBean = new FileBean();  
                        fileBean.setAbsolutePath(files[0].getAbsolutePath());  
                        fileBean.setFileSize(files[0].length());  
                        fileBean.setFilename(requestWrapper.getFileNames(paramterName)[0]);  
                        this.fileMap.put(paramterName, fileBean);  
                    }  
                    else  
                    {  
                        ArrayList<FileBean> list = new ArrayList();  
                        for (int i = 0; i < files.length; i++)  
                        {  
                            File file = files[i];  
                            FileBean fileBean = new FileBean();  
                            fileBean.setAbsolutePath(file.getAbsolutePath());  
                            fileBean.setFileSize(file.length());  
                            fileBean.setFilename(requestWrapper.getFileNames(paramterName)[i]);  
                            list.add(fileBean);  
                        }  
                        this.fileMap.put(paramterName, list);  
                    }  
                }  
            }  
        }  
  • 相关阅读:
    (紫书,感谢作者)第7章暴力求解法
    明日更新
    明天更新
    UVa11882最大的数(dfs+剪枝)
    UVa12569树上的机器人的规划
    es6中的reduce方法?
    浏览器是如何渲染页面的?
    判断是不是一个数组?
    判断是否是一个数组?
    var与let的区别?
  • 原文地址:https://www.cnblogs.com/BrightMoon/p/4148405.html
Copyright © 2011-2022 走看看