JSP + JavaBean registration verification

Source: Internet
Author: User

The source code of the example provided in this article has been uploaded by cainiao. If you are interested, go to http://download.csdn.net/detail/woshishuoshuoa/596%3 to download it ~~~

This is a simple registration verification program completed using JSP + JavaBean. You can enter the user name, age, and email address in the form. If the entered content is correct, the entered content is displayed. If the entered content is incorrect, a prompt is displayed at the wrong place, and the correct content is retained. The page for completing the program is as follows:

The register. Java code is as follows:

Package myjavabean. demo1; import Java. util. hashmap; import Java. util. map; public class register {private string name; // username private string age; // age private string email; // email address private Map <string, string> errors = NULL; // store the error information in the map public register () {// No parameter constructor this. name = ""; // initialize namethis. age = ""; // initialize agethis. email = ""; // initialize emailthis. errors = new hashmap <string, string> (); // instantiate map} public Boolean isvalidate () {// used to judge the input Whether the input information meets the requirements. If not, save the corresponding prompt information Boolean flag = true; If (! This. name. matches ("\ W {6, 15}") {// verify whether the name is valid flag = false; // modify the flag this. name = ""; // clear the error message this. errors. put ("errname", "username is 6-15 characters"); // Save the error message} If (! This. age. matches ("\ D +") {// verify whether the age is valid flag = false; // modify the flag this. age = ""; // clear the error message this. errors. put ("errage", "age can only be a number"); // save error message} If (! This. Email. Matches ("\ W + @ \ W + \. \ W + \\.? \ W + ") {// verify whether the email is valid flag = false; // modify the flag this. email = ""; // clear the error message this. errors. put ("erremail", "wrong email address format"); // save error message} return flag; // return flag} Public String geterrormsg (string key) {// retrieve the corresponding error message. This method will call string value = This in JSP. errors. get (key); // return the corresponding value from map based on the key value return value = NULL? "": Value; // The content corresponding to the returned 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 ;}}

Here, register. Java is a JavaBean file, so remember to compile register. Java first. Otherwise, an error will be reported when the JSP label in index. jsp below uses the class of this JavaBean!
The index. jsp code is as follows:

<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" GBK "%> <% string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; %> <HTML> 

The index. jsp interface simply loses a form and the register and reset buttons. Click register to jump to check. jsp.

Check. jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

Check. jsp: after obtaining the foreground data through the JSP tag, call the isvalidate () method for verification. If the verification fails, the system returns index. jsp. If the verification succeeds, the system jumps to success. jsp.

Success. jsp

<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" GBK "%> <% string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML> 

Login successful. The user name, age, email address, and registration verification program created by JSP + JavaBean are displayed ~~~ However, the registration verification program created using JSP + JavaBean is not perfect. Here is just a simple column used to consolidate the learning of JavaBean ~~~

Related Article

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.