zoukankan      html  css  js  c++  java
  • 解决web网页改变起引用的图片,刷新页面仍然显示之前的图片

    主要是tomcat服务器上的缓存引起的,只要在更新图片的时候同时给缓存更新即可

    我项目存放图片的文件夹路径 C:UsersmiaozworkspaceookWebContentimages

    然后再tomcat服务器上有个缓存空间C:Usersmiaozworkspace.metadata.pluginsorg.eclipse.wst.server.core mp0wtpwebappsookimages

    当刷新页面时图片还是从缓存空间中取,所以才会导致更新图片还是显示之前的,这里应该同时给两个路径的图片进行更新

    例如在我的项目中

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            doGet(request, response);
            String bookinfo[] = {"","","","","","","",""};
            String imagid=new Connect(1).getimag_seq();
            int count=0;
            request.setCharacterEncoding("utf-8");
            DiskFileItemFactory factory = new DiskFileItemFactory();
            String path = request.getRealPath("/images");//这是缓存中图片的路径
            factory.setRepository(new File(path));
            //设置 缓存的大小,当上传文件的容量超过该缓存时,直接放到 暂时存储室
            factory.setSizeThreshold(1024*1024) ;
            ServletFileUpload upload = new ServletFileUpload(factory);
            try {
                List<FileItem> list = (List<FileItem>)upload.parseRequest(request);
                for(FileItem item : list){
                    String name = item.getFieldName();
                    if(item.isFormField()){
                        String value = item.getString() ;
                        bookinfo[count++]=value;
                        System.out.println(name+"-->"+value);
                    }else{
                        String value = item.getName() ;
                        int start = value.lastIndexOf("\");
                        String filename = value.substring(start+1);
                        request.setAttribute(name, filename);
                        String path1=path.substring(0,path.length()-75)+"\book\WebContent\images";//这是真实项目的图片路径
                        System.out.println(path);
                        OutputStream out = new FileOutputStream(new File(path,imagid+".jpg"));
                        OutputStream out1 = new FileOutputStream(new File(path1,imagid+".jpg"));//这里同时打开两个stream,分别是缓存与真实路径
                        InputStream in = item.getInputStream() ;
                        int length = 0 ;
                        byte [] buf = new byte[1024] ;
                        while( (length = in.read(buf) ) != -1){
                            //同时将图像写入两个路径中
                            out.write(buf, 0, length);
                            out1.write(buf, 0, length);
                        }
                        in.close();
                        out.close();
                        out1.close();
                    }
                }
            }catch (FileUploadException e) {
                e.printStackTrace();
            }catch (Exception e) {
                e.printStackTrace();
            }
           
  • 相关阅读:
    MySQL distinct 与 group by 去重(where/having)
    mysql 的垂直分表和水平分表
    查看mysql语句运行时间
    PHP的性能优化方法总结
    Apache ab 压测工具使用说明
    LNMP 性能优化之 PHP 性能优化
    [PHP]日志处理error_log()函数和配置使用
    cocos2dx之tolua++全面分析(二):类注册
    在命令行上启动genymotion虚拟机
    在64位ubuntu上安装alienbrain客户端
  • 原文地址:https://www.cnblogs.com/miaos/p/11029530.html
Copyright © 2011-2022 走看看