Eclipse重启tomcat,图片加载不出来。

eclipse上传图片至服务器,每当重启服务器的时候,之前上传的图片就会清空。

解决方法:上传文件至本地,然后读取时候通过tomcat访问本地的路径。

上传:

String pic_path = "F:\\image\\"; 
        File file = new File(pic_path,c.getId()+".jpg");
        if(!file.getParentFile().exists())
            file.getParentFile().mkdirs();
        image.transferTo(file);

修改tomcat,server.xml:

path是访问路径,docBase是本地路径

<Context docBase="F:/image" path="img/category"></Context>

页面访问:

<img height="40px" src="/img/category/${c.id}.jpg">

ok了。。。

猜你喜欢

转载自blog.csdn.net/weixin_42412462/article/details/81413122