AJAX + jsp without refresh verification code examples
1, we often do when verification code due to the anti-fraud, authentication is sometimes intentionally add more of interference factors, then verify the code is not very clear display, users often enter the wrong. This will not only have to refresh the page, causing the user does not see clearly verification code and re-filling rather than modify, and save the next session if no use other data entered by the user, then (such as name), the user just input the content does not exist, so to create a bad user experience.
2, in this case the original authentication based on a paragraph js, through xmlhttp to get the return value, in order to verify the effectiveness, so that even if the user's browser does not support js, it will not affect his normal use.
3, in order to prevent cheating, when users connect 3 input error is overloaded about image, it is also beneficial to users because the picture on the verification code to identify clear and it can not enter the correct end.
4, in this case is also particularly suitable for testing the user name is valid, as long as from the background to be a sql query can return a value, or xml. (Examples of this are too much, it does not go into details here).
5, in this case the advantage is Feichang user input, and reducing server-side request, can be said to improve the user experience and strategic Hui Jie Sheng-bandwidth costs, but should go on the page Add a avascript ???, in the current speeds increasingly The sooner it an efficient and comfortable today, it seems we should pay attention to the user good use of experience.
Code:
1, img.jsp, enter the main page
< % @ Page contentType = "text / html; charset = GBK" language = "java"
import = “java.sql .*” errorPage = “” pageEncoding = “GBK”%>
< %
/ / Set Chinese Char
/ / Cody by JarryLi@gmail.com;
/ / Homepage: jiarry.126.com
request.setCharacterEncoding (”GBK”);
response.setCharacterEncoding (”GBK”);
response.setContentType (”text / html; charset = GBK”);
%>