jsp生成验证码问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 15:08:54
源代码为
<%!
Color getRandColor(int fc,int bc){//给定范围获得随机颜色
Random random = new Random();
if(fc>255) fc=255;
if(bc>255) bc=255;
int r=fc+random.nextInt(bc-fc);
int g=fc+random.nextInt(bc-fc);
int b=fc+random.nextInt(bc-fc);
return new Color(r,g,b);
}
%>
<%
//设置页面不缓存
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);

// 在内存中创建图象
int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

// 获取图形上下文
Graphics g = image.getGraphics();

//生成随机类
Random random = new Random();

// 设定背景色
g.setColor(getRandColo

看错误啊
org.apache.jasper.JasperException: /image.jsp(3,4) Page directive: illegal to have multiple occurrences of contentType with different values (old: text/html; charset=UTF-8, new: image/jpeg)

你是直接在另一个jsp里include的吧,不能指定不同的contentType

好像是编码的 问题
你和我用的都是一样的 验证码源码

但是没有出现你的问题