Because the username and password are composed of A-Z, A-Z, 0-9 characters,
I will refer to the algorithm of the regular expression, so there is a negative idea:
Judging the username and password entered by the user, see if it is these characters,
If so, login verification
Otherwise, there is an illegal character.
code show as below:
//login.jsp
<% @ page contenttype = "text / html; charset = GBK" language = "java" import = "java.io. *" ErrorPage = "error.jsp"%>
<%!
Boolean Regex (String Str) {
Java.util.regex.pattern p = null; // Regular expression
Java.util.Regex.matcher m = null; // Operation string
Boolean value = true;
Try {
P = java.util.Regex.pattern.Compile ("[^ 0-9a-za-z]");
m = p.matcher (str);
IF (m.find ()) {
Value = false;
}
} catch (exception e) {}
Return Value;
}
%>
hEAD>
<% String action = request.getParameter ("action"); IF (Action! = Null && Action.equals ("Login")) { String Username = Request.getParameter ("UserName"); String password = Request.getParameter ("password"); IF (! regex (username) ||! regex (password)) { |