Basic process of Java verification code generation

1. For the generation of verification code, we can see that it is drawn with graphics object. Object we must get the graphics object

1-1. Obtain graphics objects through bufferedimage

1-2. The general verification code background box is white

1-3. Save data (for background verification) and set font style (beautiful)

1-4. Generate specific values and randomly generated colors

1-5. General numbers are easy to be directly recognized by other software for anti black. Add a little interference line

1-6. Destroy graphics objects and store pictures

In this way, the verification code is generated. How can we import it to the foreground

2. Implementation of foreground code presentation ():

The address source of SRC is sent from the background. The path is very interesting. In step 2-1, the MyEclipse -- > SRC -- > New servlet appears as follows:

Click next to display the following page:

This configuration will be automatically to the web inf folder in the project xml。 The value in this box is the path to be accessed written in the foreground SRC, ---- > click finish. Automatically. The following interface is generated:

Here you can write the previous code. However, it should be noted that we must override this method to be effective:

The specific codes are as follows:

Foreground Code:

For the foreground code, we need to explain: when our verification code is transmitted and cannot be seen clearly, it needs to be refreshed, and the browser has the function of automatic memory. When no new parameters are transmitted, the browser will not refresh, so we need to manually write a JS control parameter transmission. We know that only time will not change, So we use time as a parameter. PS: I've been in trouble for some time: the path of the verification code. The "/" in the front end represents the Tomcat directory, which is inside the project, such as web "/" in XML indicates that the item is under. In other words, their two directories are one level away.

Finally, attach your own code during the test and the problem of modifying the digital shape. For example, the effect of changing to 2D is better. There are obvious records.

The above is about the basic process of generating verification code in Java. It also comes with your own test code. I hope these can help you.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>