求助:文件上传的时候出现的问题,求大神帮忙

java.lang.NullPointerException: charsetName
33333333331
at java.lang.String.(String.java:414)
at java.lang.String.(String.java:481)
at org.apache.commons.fileupload.disk.DiskFileItem.getString(DiskFileItem.java:375)
at com.mumu.web.controller.ManagerServlet.addProduce(ManagerServlet.java:117)
at com.mumu.web.controller.ManagerServlet.doGet(ManagerServlet.java:36)
at com.mumu.web.controller.ManagerServlet.doPost(ManagerServlet.java:161)

            DiskFileItemFactory  factory= new DiskFileItemFactory();
        //上传文件
        System.out.println("22222222222222222222");
        ServletFileUpload upload = new ServletFileUpload(factory);
         upload.setHeaderEncoding("UTF-8");
        //请求解析
        List<FileItem> items = upload.parseRequest(request);
        for(FileItem item:items){
            if(item.isFormField()){// isFormField 为空或者不是对象
                //将数据封装到JavaBean中
                System.out.println("22222222225555555555");
                String fieldName = item.getFieldName();//字段名即Javabean的属性名,除了图片
                System.out.println("000000000000");
                String fieldValue = item.getString(request.getCharacterEncoding());
                System.out.println("99999999999");
                BeanUtils.setProperty(produce,fieldName,fieldValue);
            }else{  System.out.println("2222222666666666222");
                //处理文件上传
                InputStream in=item.getInputStream();
                String fileName = item.getName();
                fileName =UUID.randomUUID()+fileName.substring(fileName.lastIndexOf("\\")+1);
                //设置存取的文件名
                System.out.println("7777777772222222");
                produce.setProimg(fileName);
                OutputStream out = new FileOutputStream(storePath+"\\"+fileName);
                byte b[] = new byte[1024];
                int len=-1;
                while((len=in.read(b))!=-1){
                    out.write(b,0,len);
                }
                out.close();
                in.close();
                item.delete();//删除临时文件
            }
        }

2个回答

不懂

String fieldValue = item.getString(request.getCharacterEncoding());
出现问题??????
求帮忙

ManagerServlet.addProduce(ManagerServlet.java:117)
.ManagerServlet.doGet(ManagerServlet.java:36)
M.anagerServlet.doPost(ManagerServlet.java:161)
这几行代码你看看
.NullPointerException: charsetName
空指针异常,这个数据获取不到

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问