• smartUpload组件文件上传


    public class SmartUploadServlet extends HttpServlet {
    
        
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            doPost(request, response);
        }
    
        
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            String filePath = getServletContext().getRealPath("/")+"images";
            File file = new File(filePath);
            if(!file.exists()){
                file.mkdir();
            }
            
            SmartUpload su = new SmartUpload();
            //初始化;
            su.initialize(getServletConfig(), request, response);
            //设置上传文件大小
            su.setMaxFileSize(1024*1024*10);
            //设置所有的上传文件的大小
            su.setTotalMaxFileSize(1024*1024*100);
            //设置允许上传文件类型
            su.setAllowedFilesList("txt,jpg,gif");
            String result = "上传成功";
            try {
                su.upload();
                su.save(filePath);
            } catch (Exception e) {
                result = "上传失败";
                if(e.getMessage().indexOf("1015")!=-1){
                    result="上传失败:上传文件类项不正确";
                }else if(e.getMessage().indexOf("1010")!=-1){
                    result="上传失败:上传文件类项不正确";
                }
                else if(e.getMessage().indexOf("1105")!=-1){
                    result="上传失败:上传文件大小大于允许上传的最大值";
                }
                else if(e.getMessage().indexOf("1110")!=-1){
                    result="上传失败:上传的总的文件大小大于允许上传的最大值";
                }
            }
            request.setAttribute("result", result);
            request.getRequestDispatcher("jsp/02.jsp").forward(request, response);
        }
    
    }
  • 相关阅读:
    给python脚本传递命令行参数
    python.exe和pythonw.exe的区别(区分.py、.pyw、.pyc文件)
    python包管理器pip
    python从新手到安装指南
    python基础知识
    使用Lua做为MMOARPG游戏逻辑开发脚本的一点体会
    游戏中各音效的音量默认值
    Unity Editor自定义菜单排序(MenuItem Order)
    没有安装vs通过Rider编译Dll
    MyBatis-Plus 代码生成器
  • 原文地址:https://www.cnblogs.com/james-roger/p/4981624.html
Copyright © 2020-2023  润新知