Code implementation of Java Web (IV) one-time verification code
In fact, the logic of the implementation code is very simple, really super simple.
1. Log in on the login page JSP uses the tag < img SRC = "XXX" > to draw the URL of the verification code picture to it
2. There are two servlets on the server side, one is the verifycodeservlet used to draw the verification code picture, and the other is the loginservlet used to verify whether the verification code is correctly clicked or repeatedly submitted during login
3. In the verifycodeservlet, save the four letters of the verification code into the session, and then in the loginservlet, compare the verification code submitted in the request with that in the session. If it is correct, the verification is successful, and the verification code in the session is deleted. Why delete it? Ensure that the data in the session can only be used once to prevent repeated submission of data. If it is incorrect, use request to save the error information, and then forward the request to the login page to display the error information. If the data in the session is found to be null, it means that the data is repeatedly submitted, and the error information is returned to the login page in the same way.
The difficulty lies in the code implementation of verifycodeservlet Not very familiar with the drawing code.
login. jsp
VerifyCodeServlet. java