Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven-Eclipse-Project我正在尝试向数据库添加一个图像,该图像不';在刷新图像之前,我不会显示在我的JSP页面中_Eclipse_Image_Maven - Fatal编程技术网

Maven-Eclipse-Project我正在尝试向数据库添加一个图像,该图像不';在刷新图像之前,我不会显示在我的JSP页面中

Maven-Eclipse-Project我正在尝试向数据库添加一个图像,该图像不';在刷新图像之前,我不会显示在我的JSP页面中,eclipse,image,maven,Eclipse,Image,Maven,这是控制器页面,我在其中添加了我的图像上传部分。 当我使用一个多部分文件将产品图像添加到我的数据库中,并且当我列出它时,一旦我刷新资源,就会显示产品缩略图-只有当我列出它时才会显示图像。 让我知道我该怎么做 @RequestMapping(value="/saveProd", method=RequestMethod.POST) public ModelAndView gotoSave(@ModelAttribute("prod")Product prod,ModelMap m, Mod

这是控制器页面,我在其中添加了我的图像上传部分。 当我使用一个多部分文件将产品图像添加到我的数据库中,并且当我列出它时,一旦我刷新资源,就会显示产品缩略图-只有当我列出它时才会显示图像。 让我知道我该怎么做

@RequestMapping(value="/saveProd", method=RequestMethod.POST)
    public ModelAndView gotoSave(@ModelAttribute("prod")Product prod,ModelMap m, Model a)
 {
     MultipartFile file = prod.getFile();
     String fileName = "";

     String image="";
     if(!file.isEmpty())
     {
          try
          { 
              System.out.println("inside try");
        fileName = file.getOriginalFilename();
        byte[] filesize=file.getBytes();
        BufferedOutputStream bout=new BufferedOutputStream(new FileOutputStream(new File("\\C:\\Users\\GOOD\\workspace\\fionazcosmetics\\src\\main\\webapp\\resources\\images\\" + fileName)));
        bout.write(filesize);
        bout.close();
        image="/resources/images/"+fileName;
        //r.setAttribute("img" ,image);
        m.addAttribute("img", image);
        System.out.println("upload sucess.."+image);

          }
          catch (IOException e) {
              System.out.println("upload failed..");
              e.printStackTrace();
          }
     }
     List<Supplier> x = supplierservice.getList();
     a.addAttribute("sList",x);
     List<Category> abc = categoryservice.getList();
     a.addAttribute("cList",abc);
     productDAOservice.insertRow(prod,image);
     List ls=productDAOservice.getList();
     return new ModelAndView("productadd","listProd",ls);
     }
@RequestMapping(value=“/saveProd”,method=RequestMethod.POST)
公共模型和视图gotoSave(@modeldattribute(“prod”)产品prod,ModelMap m,Model a)
{
MultipartFile file=prod.getFile();
字符串fileName=“”;
字符串图像=”;
如果(!file.isEmpty())
{
尝试
{ 
System.out.println(“内部尝试”);
fileName=file.getOriginalFilename();
byte[]filesize=file.getBytes();
BufferedOutputStream bout=new BufferedOutputStream(新文件(“\\C:\\Users\\GOOD\\workspace\\FionasCosmetics\\src\\main\\webapp\\resources\\images\\\”+fileName));
写(文件大小);
about.close();
image=“/resources/images/”+文件名;
//r、 setAttribute(“img”,图像);
m、 添加属性(“img”,图像);
System.out.println(“上传成功…”+图像);
}
捕获(IOE异常){
System.out.println(“上传失败”);
e、 printStackTrace();
}
}
List x=supplierservice.getList();
a、 addAttribute(“sList”,x);
List abc=categoryservice.getList();
a、 addAttribute(“cList”,abc);
productDAOservice.insertRow(prod,image);
List ls=productDAOservice.getList();
返回新的ModelAndView(“productadd”、“listProd”、ls);
}