Architecture mode comparison in the web development framework (4)

zhaozj2021-02-16  55

Page Enter Validation Validation

ASP.NET provides a server control for verification: CompareValidator verifies comparisons between two control inputs, and RangeValidator checks if the user's input is between the specified upper and lower limits; RegularExpressionValidator control checks if the input is defined with a regular expression. Pattern match (Social Security, email address, phone number, postal code, etc.); RequiredFieldValidator control ensures that the user will not skip an input; the CustomValidator control creates a custom server and client verification code. Will explain later.

The Java Web framework usually comes out of the verification rule and placed in a verification rule file. Apache Struts provides two ways to verify. One is the Validate method for overloading the org.apache.struts.Action.Actionform class, one is to define the validator plug-in file, validator-rules.xml. Apache Cocoon also provides similar verification rule files. A later illustration.

ASP.NET example

From the .NET framework document, the rest is omitted, and only the part of the RegularExpressionValidator is retained. In this example, the ControlTovAlidate property of the Control for the regularExpressionValidator1 is TextBox1, so RegulaRexpressionValidator1 is responsible for verifying whether TextBox1 meets the regular expression "/ d {5}" - 5 numbers.

Runat = "server" />

ID = "RegularExpressionValidator1"

ControlTovAlidate = "TextBox1"

ValidationExpression = "/ d {5}"

DISPLAY = "static"

EnableClientScript = "false"

ErrorMessage = "Zip code Must Be 5 Numeric Digits"

Runat = "server" />

An example of Apache Struts

The following example is extracted from the user document of Apache Struts. The Validation mechanism provided by Apache Struts is very powerful, enabling conditional verification based on other input domains, that is, if another or several input domains meet the appropriate case, verify that the current domain meets a certain condition.

Property = "firstname" indexedlistproperty = "dependents"

Depends = "Requiredif">

Field [0]

LastName

Field-indexed [0]

True

Field-test [0]

notnun

Property = "DOB"

IndexedListProperty = "dependents"

Depends = "Requiredif, Date">

Field [0]

LastName

Field-indexed [0]

True

Field-test [0]

notnun

Property = "coveragetype"

IndexedListProperty = "dependents"

Depends = "Requiredif">

Field [0]

LastName

Field-indexed [0]

True

Field-test [0]

notnun

Field [1]

InsureDependents

Field-test [1]

Equal

Field-value [1]

True

Field-join and

Apache Cocoon

The following example is the file in the teaching program of Apache Cocoon. Verify the ID and NAME two domains. At the same time, this file defines the binding between page elements and database data. The next section will explain this problem.

Personnel

Database Driven Page

As shown in the last section of the last section, many web development frameworks provide direct binding of page elements and database fields.

The .NET framework contains three controls that make a large amount of data: Repeater control, DataList control, and DataGrid controls. These three controls use similar data binding procedures, bind to DataSet, SqlDataReader or DataView. The following code example is extracted from the .NET Framework document, showing how the DataSet returned by the SQL database query is binded to the DataGrid control.

<% @ Import namespace = "system.data"%>

<% @ Import namespace = "system.data.sqlclient"%>