图片上传,求大神解决 头疼啊

 public void insert(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            DiskFileItemFactory factory = new DiskFileItemFactory();
            String path = req.getRealPath("/upload");
            System.out.println(path);
            factory.setRepository(new File(path));
            factory.setSizeThreshold(1024 * 1024);
            ServletFileUpload upload = new ServletFileUpload(factory);
            List<FileItem> ls = upload.parseRequest(req);
            for (FileItem item : ls) {
                if (item.isFormField()) {
                    String name = item.getFieldName();
                    String value = item.getString("gbk");
                    System.out.println(name); //name 里面有我的普通参数,我需要把参数那出来, 放到我的数据库里面,我不知道怎么单个拿出来
                    System.out.println(value);
                    req.setAttribute(name, value);
                } else {
                    String name = item.getFieldName();
                    String value = item.getName();
                    int start = value.lastIndexOf("\\");
                    String fileName = value.substring(start + 1);
                    System.out.println(fileName);
                    req.setAttribute(name, fileName);
                    Encoding en = new Encoding();
                    OutputStream os = new FileOutputStream(new File(path, fileName));
                    InputStream is = item.getInputStream();
                    byte[] bt = new byte[400];
                    int length = 0;

                    while ((length = is.read(bt)) > 0) {
                        os.write(bt, 0, length);
                    }
                    String comment = path + "\\" + value;

                    os.close();
                    is.close();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

https://zhidao.baidu.com/question/648676764436220285.html

name是一个什么样的值呢!

用smartupload做的图片上传 很简单 http://blog.csdn.net/u014362204/article/details/64129017

http://blog.csdn.net/xuanzhangran/article/details/54928997

保存之后在数据库里了,怎么会消失呢