This function mainly uses the JSP page to generate the verification code, realizes the page to refresh through the original javascript+iframe. The steps are as follows:
1. Verification Code Generation page valicode.jsp:
<%@ page language= "java" import= "java.util.*,java.io.*,com.sun.image.codec.jpeg.*,java.awt.*,java.awt.image.*" pageencoding= "GB18030"%>
<%
String s= "";
int count=0;
Random rand=new Random ();
Count=rand.nextint (9999);
while (count<1000) {
count=rand.nextint (9999);
}
S+=count;
Session.setattribute ("Validate", s);
Response.setcontenttype ("Image/gif");
BufferedImage image=new BufferedImage (65,30,BUFFEREDIMAGE.TYPE_INT_RGB);
Graphics gra=image.getgraphics ();
Gra.setcolor (color.red);
Gra.fillrect (1,1,63,28);
Gra.setcolor (color.orange);
Gra.setfont (New Font ("Official script", font.plain,28));
char c;
for (int i=0;i<4;i++) {
C=s.charat (i);
Gra.drawstring (c+ "", i*15+4,23);
}
OutputStream Toclient=response.getoutputstream ();
JPEGImageEncoder Jpg=jpegcodec.createjpegencoder (toclient);
Jpg.encode (image);
Toclient.close ();
Out.clear ();
Out=pagecontext.pushbody ();
%>
2, set refresh page code.jsp:
The main introduction of the Verification code picture, click Refresh.
3, in the theme page index.jsp surface using IFRAME, the introduction of verification code
<iframe id= "MyFrame" width= "height=" src= "/company/code.jsp" scrolling= "no" ></iframe>
4, click can realize refresh.
5, a more simple way, in the theme page index.jsp page can be directly using the OnClick implementation request Refresh
valicode.jsp' onclick= ' document.getElementById (' Imgvcode '). src = ' valicode.jsp? ' + (new Date ()). GetTime () "/>
Later time can change the address, the equivalent of a different request, the page to achieve the refresh effect.