A general method for form data storage in JSP

Source: Internet
Author: User
Tags insert sql

Introduction

Java 2 Enterprise Edition technology has been widely used in Web application development, in which the JavaBean, servlet technology for developers to provide a clearer development environment, using JSP Technology Performance page, Use servlet technology to do a lot of business processing, using beans to store data and some business processing. In Web applications, business data stored in the database processing work is often very heavy, one of the main forms is the form of data storage to the database, the entire application process involves a large number of such data storage operations, each form to write the corresponding data storage program, It cost the developer a lot of time and effort. What methods are used to mitigate the development workload of form data storage is a problem worth studying.

Two common forms of data storage processing methods

1, for each form to write the appropriate program code

In a JSP page or JavaBean or servlet, use request. The GetParameter () function extracts the data submitted by the form individually, or writes the corresponding JavaBean, uses the SetProperty method to automatically fetch the data into the JavaBean, and then generates the SQL statement (Insert,update,delete). Finally, execute the executeupdate () function to complete the data table store.

2. Automatically generate a JavaBean program code for each datasheet

The database system must support the ability of users to read the table structure and identify key fields. Using object-oriented rapid development tools, such as PowerBuilder, Delphi, and so on, the development of a Java code automatic generation program. Read the structure of the database table in the Program: field name, data type, data length, and automatically generate a JavaBean code. In this code, define the variable with the same name as the field in the table, establish the SetValue and GetValue methods for all the variables, and establish the INSERT, update, and delete functions to handle the SQL statement generation and execution of INSERT, UPDATE, delete, respectively.

In the Data processing page submitted by the form, write the following code to store the form data in JavaBean:

<jsp:useBean id="table" class="table1_bean" />
<jsp:setProperty name="table" property="*" />
(注:table1_bean为上述自动生成的对应某一个表的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.