.nextInt(110), 20 + random.nextInt(110)));
g.drawString(String.valueOf(ctmp), 15 * i + 10, 16);
} else if (random.nextInt(3) == 1) {
itmp = random.nextInt(26) + 97;
char ctmp = (char) itmp;
sRand += String.valueOf(ctmp);
g.setColor(new Color(20 + random.nextInt(110), 20 + random
.nextInt(110), 20 + random.nextInt(110)));
g.drawString(String.valueOf(ctmp), 15 * i + 10, 16);
} else {
itmp = random.nextInt(9);
sRand += String.valueOf(itmp);
g.setColor(new Color(20 + random.nextInt(110), 20 + random
.nextInt(110), 20 + random.nextInt(110)));
g.drawString(String.valueOf(itmp), 15 * i + 10, 16);
}
}
HttpSession session = request.getSession(true);
session.setAttribute("checkcode", sRand);
g.dispose();
try {
ImageIO.write(image, "JPEG", response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
}
2.在struts.xml中
[html]
cacodet
cacodet
3.在register.jsp中
[html]
<script type="text/java script">
function reImg(){
var img = document.getElementById("picture");
img.src=img.src + " ";
}
<script type="text/java script">
function reImg(){
var img = document.getElementById("picture");
img.src=img.src + " ";
}
4.效果如下:
