Use Javabean to complete registration

Source: Internet
Author: User
Register. Java // used to generate a JavaBean  

Package info. haowei. JavaBean; 2 3 Import java. util. hashmap; 4 Import java. util. Map; 5 6 Public class register { 7 8 Private string name; 9 Private string age; 10 Private string email; 11 Private Map <string, string> errors = Null ; 12 13 14 15 Public Register (){ 16 This . Name = "" ; 17 This . Age = ""; 18 This . Email = "" ; 19 This . Errors = New Hashmap <string, string> (); 20 } 21 Public String getname (){ 22 Return Name; 23 } 24 Public Void Setname (string name ){ 25 This . Name = Name; 26 } 27 Public String getage (){ 28 Return Age; 29 } 30 Public Void Setage (string age ){ 31 This . Age = Age; 32 } 33 Public String getemail (){ 34 Return Email; 35 } 36 PublicVoid Setemail (string email ){ 37 This . Email = Email; 38 } 39 40 Public Boolean Isvalidate (){ 41 Boolean Flag = True ; 42 If (! This . Name. Matches ("\ W {6, 15 }" )){ 43 Flag = False ; 44 This . Name = "" ; 45 This . Errors. Put ("errorname", "username is a 6-15 digit number" ); 46 } 47 If (! This . Email. Matches ("\ W + @ \ W + \. \ W + \\.? \ W *" )){ 48 Flag = False ; 49 This . Email = "" ; 50 This . Errors. Put ("erroremail", "invalid email address" ); 51 } 52 If (! This . Age. Matches ("\ D +" )){ 53 Flag = False ; 54 This . Age = "" ; 55 This . Errors. Put ("errorage", "Age input is invalid" ); 56 } 57 58 Return Flag; 59 } 60 61 Public String geterrormsg (string key ){ 62 String value = This . Errors. Get (key ); 63 If (Value = Null ){ 64 Return "" ; 65 } 66 Return Value; 67 } 68 69 70 71 }

 

 

// Check. jsp is used to determine whether the input is correct

<% @ Page contenttype = "text/html" pageencoding = "GBK" %> <HTML> //Solve the garbled problem %><JSP: usebean id = "Reg" Scope = "request" class = "info. haowei. javaBean. register "/> <JSP: setproperty property =" * "name =" Reg "/> <body> <%If(Reg. isvalidate ()){%> <JSP: Forward page = "success. jsp"> </jsp: Forward> <%}Else{%> <JSP: Forward page = "index. jsp"> </jsp: Forward ><%}%> </body>  

 

// Index. jsp uses form input and transmits information through JavaBean

1 <% @ Page contenttype = "text/html" pageencoding = "GBK" %> 2 <HTML> 3 <Head> 4 </Head> 5 <% Request. setcharacterencoding ("GBK "); //  Solve the garbled problem %>  6 <JSP: usebean id = "Reg" Scope = "request" class = "info. haowei. JavaBean. Register"/> 7     8 <Body> 9 <Form action = "check. jsp" method = "Post"> 10 Username: <input type = "text" name = "name" value = "<JSP: getproperty name =" Reg "property =" name "/>"/> 11 <% = Reg. geterrormsg ("errorname") %> <br> 12 Age: <input type = "text" name = "Age" value = "<JSP: getproperty name =" Reg "property =" Age "/>"/> 13 <% = Reg. geterrormsg ("errorage") %> <br> 14 Email: <input type = "text" name = "email" value = "<JSP: getproperty name =" Reg "property =" email "/>"/> 15 <% = Reg. geterrormsg ("erroremail") %> <br>16       17 <Input type = "Submit" value = "Submit"> 18 <Input type = "reset" value = "reset"> 19 </Form> 20 </Body> 21 </Html>

 

// Registration successful page

 1 <% @ Page contenttype = "text/html" pageencoding = "GBK" %> 2 <HTML> 3 <Head> 4 </Head>5 <% Request. setcharacterencoding ("GBK "); //  Solve the garbled problem %>  6 <JSP: usebean id = "Reg" Scope = "request" class = "info. haowei. JavaBean. Register"/> 7     8 <Body> 9       10 Username: <JSP: getproperty name = "Reg" property = "name"/> <br> 11    12 Age: <JSP: getproperty name = "Reg" property = "Age"/> <br> 13  14 Email: <JSP: getproperty name = "Reg" property = "email"/> <br> 15   16       17       18 </Body> 19 </Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.