JSP Form Fill Validation---Jsp+javabean

Source: Internet
Author: User

1, JavaBean

The so-called JavaBean is a Java class that satisfies certain design rules, and the rules to be met are as follows

(1) The attribute of the data member is private

(2) Setxxx and GetXXX methods for each data member that has the public attribute

(3) A constructor for a public type with no parameters

2. Instance Code

Package Bean;public class Usercheckbean{private string Name;public Usercheckbean () {}public Usercheckbean (String name) { This.name=name;} public void SetName (String name) {this.name=name;} Public String GetName () {return name;} public Boolean validate () {return name.equals ("CJC");}}
Login interface

<! DOCTYPE html>
Validating JSPs

<%@ page language= "java" contenttype= "text/html; Charset=iso-8859-1 "    pageencoding=" Iso-8859-1 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" ><%@ page Import= "Bean. Usercheckbean "%><jsp:usebean id=" user "scope=" session "class=" Bean. Usercheckbean "/><jsp:setproperty name=" user "property=" name "value=" * "/><%string nm= Request.getparameter ("name"); User.setname (nm); Usercheckbean uc=new Usercheckbean (nm), if (Uc.validate ()) {%><jsp:forward page= "welcome.jsp"/><%}else{ Out.println ("The username does not exist!"); o Ut.println ("<a href=\" login.html\ ">login again</a>");} %>
Welcome interface

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



JSP Form Fill Validation---Jsp+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.