In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what are the general methods of form data storage in JSP technology. I hope you will get something after reading this article. Let's discuss it together.
J2EE (Java 2 Enterprise Edition) technology has been widely used in Web application development, in which JavaBean and Servlet technology provides a clearer development environment for developers, using JSP technology to represent pages, using Servlet technology to complete a large number of business processing, using Bean to store data and some business processing. In WEB applications, the processing of business data stored in the database is often onerous, and one of the main forms is form data storage to the database. The whole application processing process involves a large number of such data storage operations. It takes a lot of time and energy for developers to write a corresponding data storage program for each form. What method to use to reduce the development workload of form data storage is a problem worth studying.
Two common methods of form data storage and processing
1. Write the corresponding program code for each form
In JSP pages or JavaBean or Servlet, use request. Exe. 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 into the JavaBean, then generates the SQL statement (insert,update,delete), and * * executes the executeupdate () function to complete the data table storage.
2. Automatically generate a JavaBean program code for each data table
The database system must support the user's ability to read the table structure and identify key fields. An automatic Java code generation program is developed by using object-oriented rapid development tools, such as PowerBuilder, Delphi and so on. In this program, read the structure of the database table: field name, data type, data length, and automatically generate a JavaBean code. In this code, the variables with the same name corresponding to the fields in the table are defined, the setValue and getValue methods of all variables are established, and the functions of insert, update and delete are established to handle the generation and execution of SQL statements of insert, update and delete respectively.
On the data processing page of the form submission, write the following code to store the form data in JavaBean:
< jsp:useBean id= table "class=" table1_bean "/ > < jsp:setProperty name=" table "property=" * "/ >
Then call the insert, update, delete functions in table1_bean to complete the data table storage and return the execution result. Such as:
<% boolean success = table.insert ();% >
* the method is simple and intuitive, but you need to write a corresponding data processing program for each form. For slightly larger applications, the number of forms may be large, the development workload is heavy, and the development work is inefficient. When the table structure changes, such as adding or decreasing fields, it is necessary to modify the corresponding data processing program.
The second method is much simpler than *. The data processing of each data table is realized by the corresponding JavaBean, and JavaBean is automatically generated without writing. When the table structure changes, you only need to generate a new JavaBean, and overwrite the original Java class after being compiled by Java. However, this method requires the development of an automatic JavaBean generation program, and JavaBean needs to be regenerated and compiled when the table structure changes.
This paper introduces a simple and general method to realize form data storage.
In WEB application development, many forms are submitted to the background server after simple data verification in the foreground browser. The server stores the data in a data table without any processing. In this case, we can write only one program, deal with these forms uniformly, and store the data in a corresponding data table. This method also requires the database system to support table structure reading and key field recognition. We use JSP technology to write the program, and the program file is named DbdataStore.jsp.
1. Call format
The Action call method for the form in the web page is as follows:
< Form Name=Frm1 Method=Post Action= "DBdataStore.jsp?
Tablename=table1&OperType=... ">
Table1 is the table name of the database table that the data will store. There are three types of OperType operations: insert,update,delete.
< input type=text name= in the form... >, < textarea name=... > < select name=... > the name value in the table should be the same as the field name in the data table. DBdataStore.jsp extracts the data value of the corresponding field name submitted by the form one by one. If no input is defined in the form, the resulting value is null, then the field will not be processed.
2. View definition taking oracle as an example
1) create a view of the data types of each column of 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 datasheet.
2) create the key column view of the table
CREATE OR REPLACE VIEW v_pkey_column AS
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. Ownery account user1 'AND a. Intact typeship account P'
After reading this article, I believe you have a certain understanding of "what are the general methods of form data storage in JSP technology". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.