解决firefox下验证码gif图只显示第一帧的问题

InputStream is = null;
		OutputStream os = null;
		ByteArrayOutputStream baos = null;


			response.setHeader("Pragma","No-cache");
			response.setHeader("Cache-Control","no-cache");
			response.setDateHeader("Expires", 0);
			response.setHeader("Content-Type", "image/gif");
			// 输入字节流
			is = new BufferedInputStream(new FileInputStream(filename));
			// 输出字节流
			baos = new ByteArrayOutputStream();
			// 定义response的输出流
			os = new BufferedOutputStream(response.getOutputStream());

			// 4K输出BUFFER
			byte[] buffer = new byte[4 * 1024];
			int read = 0;

			// 从文件中读入数据并写到输出字节流中
			while ((read = is.read(buffer)) != -1) {
				baos.write(buffer, 0, read);
			}
			baos.flush();	
		        response.setHeader("Content-Length",String.valueOf(baos.size()));
			
			//将输出字节流写到response的输出流中
			os.write(baos.toByteArray());			
			os.flush();
			response.flushBuffer();


首先在head中加入Content-Length:

response.setHeader("Content-Length",String.valueOf(baos.size()));
但是加入者之后部分火狐浏览器可以正常访问,还有少数偶尔会出现空白帧,最后在src赋值的地方找到了原因:

$("#verifyCodeImg").attr("src","");//解决火狐下验证码刷不出的问题
$("#verifyCodeImg").attr("src",data.verifyCodeImgUrl);
先="",在赋值就没问题了;




你可能感兴趣的:(JS及JQuery,J2EE)