Java Web Note: Registration validation of JavaBean instances

Source: Internet
Author: User

This article is to write a Jsp+javabean completed user registration program, the main logic is: User input form Content-sent to JavaBean for verification-verification successfully jump to the details page-validation failure indicates an error.

The main pages are:

index.jsp, check.jsp, success.jsp, Register.java


Register.java

Package Com.zzh.test;import Java.util.hashmap;import Java.util.map;public class Register {private String name;private  String Age;private string Email;private map<string, string> errors = Null;public Register () {this.name = ""; this.age = ""; this.email = ""; this.errors = new hashmap<string, string> ();} public Boolean isvalidate () {Boolean flag = True;if (!this.name.matches ("\\w{6,15}")) {flag = False;this.name = ""; errors. Put ("Errname", "username is a 6-15-bit letter or number!") ");} if (!this.email.matches ("\\[email protected]\\w+\\.\\w+\\.? \\w* ") {flag = False;this.email =" ", Errors.put (" Erremail "," the email address entered is illegal! ") ");} if (!this.age.matches ("\\d+")) {flag = False;this.age = ""; Errors.put ("Errage", "age can only be numbers!") ");} return flag;} public string geterrormsg (string key) {String value = This.errors.get (key); return value = = null? "": value; Public String GetName () {return name;} public void SetName (String name) {this.name = name;} Public String Getage () {return age;} public void Setage (String age) {this.age =Age;} Public String Getemail () {return email;} public void Setemail (String email) {this.email = email;}}


index.jsp

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >


check.jsp

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >


success.jsp

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >



Java Web Note: Registration validation of JavaBean instances

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.