首页新闻找找看学习计划

uploadify中的upload.parseRequest(request)为空

0
悬赏园豆:20 [已关闭问题] 关闭于 2017-07-13 11:02

用uploadify上传文件,结果到action中,upload.parseRequest(request)的得到的一直为空,action内容:

DiskFileItemFactory  factory = new DiskFileItemFactory();  
        factory.setSizeThreshold(20 * 1024 * 1024); //设定使用内存超过5M时,将产生临时文件并存储于临时目录中。     
        factory.setRepository(new File(tempPath)); //设定存储临时文件的目录。     
        ServletFileUpload upload = new ServletFileUpload(factory);  
        upload.setHeaderEncoding("UTF-8");
        try {  
            List items = upload.parseRequest(request);  
            Iterator itr = items.iterator();  
            System.out.println("items--"+items);  
            while (itr.hasNext()) {  
                FileItem item = (FileItem) itr.next();  
                String fileName = item.getName();  
                if (!item.isFormField()) {  
                    String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();  
                    SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");  
                    newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt;  
                    try{  
                        File uploadedFile = new File(savePath, newFileName);  
                        OutputStream os = new FileOutputStream(uploadedFile);  
                        InputStream is = item.getInputStream();  
                        byte buf[] = new byte[1024];//可以修改 1024 以提高读取速度  
                        int length = 0;    
                        while( (length = is.read(buf)) > 0 ){    
                            os.write(buf, 0, length);    
                        } 

 

web.xml也有加<filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>*.action</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>.

也有加MyRequestParser类,struts.xml<bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest"
          name="myRequestParser" class="com.aachen.utils.MyRequestParser"
          scope="default" optional="true"/>
    <constant name="struts.multipart.parserr" value="myRequestParser" />,网上说的这2个方法都不行。

蜗牛丶sky的主页 蜗牛丶sky | 初学一级 | 园豆:10
提问于:2016-03-14 14:02
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册