盗QQ密码需求前台展示图片,之前系统是从服务器磁盘路径中读取
盗QQ密码需求前台展示图片,之前系统是从服务器磁盘路径中读取,当图片数量多的时候,由于读写操作耗时,就会导致页面出现卡的感觉。
解决方案:使用缓存技术,在第一次浏览过图片之后,将图片的byte[]流缓存到MAP中,下次在访问的时候直接缓存获取就可以。
样例代码:
jsp调用方式如下:
在src中写入要跳转的地址,我这里用的是struts2
后台类的写法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
public void loadImage() throws Exception { ActionContext context = ActionContext.getContext(); HttpServletResponse imgResponse = (HttpServletResponse) context .get(ServletActionContext.HTTP_RESPONSE); HttpServletRequest imgRequest = (HttpServletRequest) context .get(ServletActionContext.HTTP_REQUEST); String picName = imgRequest.getParameter( "picName" ); String[] picNames = picName.split( "/" ); String url = Constant.HDFS_PREFIX + Constant.HDFS_AD_PREFIX + picNames[picNames.length - 1 ]; // 根据URL获取图片流 byte [] picStream = ImgUtil.AD_PIC_MAP.get(url); InputStream in = new ByteArrayInputStream(picStream); BufferedOutputStream bout = new BufferedOutputStream( imgResponse.getOutputStream()); try { byte b[] = new byte [ 1024 ]; int len = in.read(b); while (len > 0 ) { bout.write(b, 0 , len); len = in.read(b); } } catch (Exception e) { e.printStackTrace(); } finally { bout.close(); in.close(); } } |
以上是我工程的代码,可参照改成自己的项目
- 上一篇:黑客QQ如何打造自己的QQ密码破解器
- 下一篇:dedecms 版本漏洞-盗号网站