日期:2014-05-20 浏览次数:20890 次
<form action="<c:url value='/pub/uploadTeSearch.htm'/>" enctype='multipart/form-data" method="POST">
request.setCharacterEncoding("UTF-8");
            response.setContentType("text/html; charset=UTF-8");
            SmartUpload mySmartUpload = new SmartUpload();
            
            //上传初始化
            mySmartUpload.initialize(this.getServletConfig(), request, response);
            //上传
            mySmartUpload.upload();
            logger.debug("正在上传...");
            mySmartUpload.getFiles().getSize();
            File myfile = mySmartUpload.getFiles().getFile(0);
            if( myfile != null ){
                String sufix = myfile.getFileExt().toLowerCase();
                if(ServiceUtil.isNotNull(sufix)){
                    if(!sufix.endsWith("doc")){
                        throw new MessageRuntimeException("只能上传后缀名为 doc的文档!!!");
                    }
                }
            }
                
    SmartUpload su=new SmartUpload();
              su.initialize(pageContext);             
           su.upload();
              com.jspsmart.upload.File file = su.getFiles().getFile(0);               if(file.isMissing()==false)//判断是否存在
       {file.saveAs("" ,su.SAVE_VIRTUAL);}