Common Methods of form data storage in JSP Technology

Source: Internet
Author: User

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 and use JSP technology to present pages, servlet technology is used to process a large amount of services, and Bean is used to store data and process some services. 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

In JSP pages, JavaBean, or Servlet, use request. the getparameter () function extracts the data submitted by the form one by one, or writes the corresponding JavaBean, uses the setProperty method to automatically fetch the data to the JavaBean, and then generates the 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:

 
 
  1. <jsp:useBean id="table" class="table1_bean" />  
  2. <jsp:setProperty name="table" property="*" />  

Then, the insert, update, and delete functions in tabledomainbean are called to store data tables and return execution results. For example:

 
 
  1. <%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 technology to write this program. The program file is named DbdataStore. jsp.

1. Call format

The form Action on the webpage is called as follows:

 
 
  1. <Form Name=Frm1 Method=Post Action="DBdataStore.jsp? 
    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. in jsp, the data values of the corresponding field names submitted by the form are extracted one by one. If the input is not defined in the form and the obtained value is null, this field is not processed.

2. view definition using oracle as an Example

1) create a data type view for each column in the table

Create or replace view v_dbstru as select table_name, column_name, data_type, data_length, data_precision, data_scale, column_id

FROM all_tab_columns WHERE owner = 'user1'; // user1 is the owner of the data table.

2) create a key column view for the table

Create or replace view v_pkey_column

SELECT B. table_name, B. column_name, B. position

FROM all_constraints a, all_cons_columns B

WHERE a. owner = B. owner AND a. constraint_name = B. constraint_name AND a. owner = 'user1' AND a. constraint_type = 'P ';

This article takes Oracle database as an example to introduce a simple and common form data storage processing method for developing WEB applications using JSP technology to reduce the development workload and provide the main program code.

  1. Introduction to JSP Technology
  2. Introduction to ASP and JSP pages
  3. Create a message board with JSP program
  4. How to become a good JSP programmer
  5. JSP tag library Introduction

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.