Using the IFRAME implementation, click on the JSP page in the code refresh __jsp

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.