Bd. jsp
<% @ Page contentType = "text/html; charset = gb2312" %>
<% // String that accepts form submission,
/*
An example of a regular expression where data can only be a-z, A-Z, 0-9 characters.
Regular Expressions are very important in the process of program login. Otherwise, you can easily bypass your degree of judgment by using 'or' and other statements;
Author: Gao Song QQ: 932246 a simple example but very useful, hope to play a role.
*/
String temp = "I am an invalid character ";
String name = request. getParameter ("name"); // The amount to be paid.
String pass = request. getParameter ("pass ");
If (name = null ){
Name = temp;
}
If (pass = null ){
Pass = temp;
}
%>
<%! Private 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;
}
%>
<Html>
<Title> Information Input Form </title>
<Body>
<Form action = "bd. jsp" method = "get">
<Div align = "center"> <font color = "# FF0000"> example of regular expressions where data can only be a-z, A-Z, 0-9 Characters </font>
<Table border = "1">
<Tr>
<Td bgcolor = "yellow"> User </td>
<Td> <input name = "name" type = "text" id = "name"> </td>
</Tr>
<Tr>
<Td width = "293" bgcolor = "yellow"> password </td>
<Td width = "240"> <input name = "pass" type = "text" id = "input"> </td>
</Tr>
<Tr>
<Td colspan = "2" align = "center"> <input name = "submit" type = "submit" value = "OK">
<Input name = "reset" type = "reset" value = "cancel">
</Td>
</Tr>
<Tr>
<Td colspan = "2" align = "center"> message prompt
<%
// Judgment:
If (! Regex (name )){
Out. print ("the user name can only be a-z, A-Z, 0-9 characters ");
Return; // exit the program only
}
Out. print ("Congratulations, your data entry is legal. <Br> "+" the name you entered is: "+ name +" <br> the password you entered is: "+ pass );
%>
</Td>
</Tr>
</Table>
</Div>
</Form>
</Body>
</Html>