First, the e-mail class is created to inherit the serializable interface to enable its serialization, and serialization is to maintain the compatibility of the version, that is, deserialization still preserves the uniqueness of the object during version upgrade . The serialized interface has no methods or fields and is used only to identify the semantics of serializable. The method is implemented by java.io.Serializable, and classes that do not implement this interface will not be able to serialize or deserialize their any state, in fact I do not write "private static final long serialverionuid = 1l;" There is a null pointer problem, so pay attention to the serializable interface here. In fact, in my understanding serializable is the Java provides universal data saving and reading interface, any type implements the Serializable interface, can be saved to a file, or as a data stream sent over the network to other files or programs, greatly simplifying the design of the class.
Package Com.caiduping.bean;import Java.io.serializable;public class Email implements Serializable {@SuppressWarnings ( "Unused")//serialization (serialization) is a procedure that describes an object in a series of bytes//serialversionuid variable name private static final long Serialverionuid = 1l;/ /email Address private string mailadd;//is a standard email address private boolean email;public email () {} public email (string Mailadd) {this.mailadd = Mailadd;} Verify the mailbox format public Boolean isemail () { String check = "^ ([a-z0-9a-z]+[-|_|\\.]?) +[a-z0-9a-z]@ ([a-z0-9a-z]+ (-[a-z0-9a-z]+) \ \.) +[a-za-z]{2,}$ "; if (mailadd.matches (check)) { email = true; } return email; } Public String Getmailadd () {return mailadd; } public void Setmailadd (String mailadd) { this.mailadd = Mailadd; }}
First page index.jsp:
<form id= "Form1" Name= "Form1" method= "Post" action= "result.jsp" > <div align= "center" > <table Width= "530" border= "1" > <tr> <td colspan= "2" ><div align= "center" ><span class= " STYLE1 "> Email authentication system </span></div></td> </tr> <tr> <td width=" 293 "> <div align= "center" ><span class= "STYLE2" > Email address:</span></div></td> <td width= " 221 "><label> <input type=" text "name=" Mailadd "/> </label></td> </tr > <tr> <td colspan= "2" ><label> <div align= "center" > <input Type = "Submit" Name= "Submit" value= "Submission Enquiry"/> </div> </label></td> </tr> </table> </div></form>
Finally, write the result page result.jsp:
<% String mailadd = Request.getparameter ("Mailadd"); email email = new email (mailadd); if (Email.isemail ()) { out.print (mailadd+ "<br> is a standard email address!) <br> "); } else{ out.print (mailadd+ "<br> not a standard email address! <br> "); } %> <a href= "index.jsp" > Back </a>
Run:
JSP mailbox Check