A common method for storing form data in JSP

Source: Internet
Author: User

Abstract

This article takes Oracle (a large-scale website database platform) as an example to introduce a simple and common form data storage and processing method for developing WEB applications using jsp (preferred for SUN Enterprise applications, to reduce the development workload and provide the main program code.

Introduction

J2EE (Java 2 Enterprise Edition) technology has been widely used in Web application development. the JavaBean and Servlet technologies provide developers with a clearer development environment, use jsp (preferred for SUN enterprise-level applications) technology presentation page, use Servlet technology to complete a large number of business processing, and use Bean to store data and some business processing. In WEB applications, the processing of business data stored in the database is often very heavy. One of the main forms is the storage of form data to the database, the entire application processing process involves a large number of such data storage operations. Each form requires independent Writing of corresponding data storage programs, which takes a lot of time and effort by developers. It is worth studying how to reduce the development workload of form data storage.

Two common forms data storage and processing methods

1. Write the corresponding program code for each form

On the jsp (preferred for SUN Enterprise Applications) page or JavaBean or Servlet, use request. the getparameter () function extracts the data submitted by the form one by one, or writes the corresponding JavaBean, automatically retrieves the data to the JavaBean using the setProperty method, and then generates an SQL statement (insert, update, delete ), finally, execute the executeupdate () function to complete data table Storage.

2. automatically generate a JavaBean program code for each data table

The database system must support reading table structures and identifying key fields. Develop a java code automatically generated program by using object-oriented rapid development tools such as PowerBuilder and Delphi. Read the structure of the database table in this program: field name, data type, Data Length, automatically generate a JavaBean code. Define the variable with the same name as the field in the table in this Code, and create the setValue and getValue methods for all variables, create insert, update, and delete functions to generate and execute SQL statements of insert, update, and delete.

On the data processing page of Form submission, write the following code to store form data to the JavaBean:

<Jsp (preferred for SUN Enterprise Applications): useBean id = "table" class = "tabledomainbean"/>
<Jsp (preferred for SUN Enterprise Applications): setProperty name = "table" property = "*"/>
(Note: table‑bean is the automatically generated an corresponding to a table)
Then, the insert, update, and delete functions in tabledomainbean are called to store data tables and return execution results. For example:
<% Boolean success = table. insert (); %>

The first method is simple and intuitive, but the corresponding data processing program needs to be compiled for each form. For a slightly larger application, the number of forms may be large, the development workload is large, and the development efficiency is low. When adding or decreasing fields in a table structure change, you must modify the corresponding data processing program.

The second method is much easier than the first method. The data processing of each data table is implemented by the corresponding JavaBean, which is automatically generated by the JavaBean without writing. When the table structure changes, you only need to generate a new JavaBean, after java compilation, it is enough to overwrite the original java class. However, this method requires the development of a JavaBean Automatic Generation Program. When the table structure changes, the JavaBean needs to be re-generated and compiled.

This article introduces a simple and common method to store form data.

In WEB application development, many forms are submitted to the backend server after simple data verification on the front-end browser. The server directly stores the data in a data table without any processing. In this case, we can write only one program to process these forms in a unified manner and store the data in the corresponding data table. This method also requires the database system to support table structure reading and key field identification. We use jsp (the first choice for SUN Enterprise Applications) technology to write this program. The program file is named DbdataStore. jsp (the first choice for SUN Enterprise applications ).

1. Call format

The form Action on the webpage is called as follows:

<Form Name = Frm1 Method = Post Action = "DBdataStore. jsp (preferred for SUN Enterprise Applications )? Tablename = table1 & OperType =... ">

Table1 is the name of the database table to be stored. OperType operations are classified into three types: insert, update, and delete.
<Input type = text name =...>, <Textarea name =...> <Select name =...> The name value in the parameter must be the same as the field name in the data table, DBdataStore. jsp (preferred for SUN Enterprise Applications) extracts the data values of the corresponding field names submitted by the form one by one. If the input is not defined in the form and the obtained value is null, this field is not processed.

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.