How to implement records in the Struts database application
[Related Links]
"JavaWebstudio Series Development Tools Visaul Struts Version" http://dev.9cbs.net/develop/Article/28/28871.shtm
"How to achieve the simplest Struts program" http://dev.9cbs.net/develop/Article/28/28946.shtm
"The implementation of the Struts drop-down box" http://dev.9cbs.net/develop/Article/28/28956.shtm
"The implementation of the Sruts radio box" http://dev.9cbs.net/develop/Article/29/29042.shtm
"Struts check box" http://dev.9cbs.net/develop/Article/29/29043.shtm
"The relationship between the Struts programs (1)" http://dev.9cbs.net/develop/Article/29/29131.shtm
The relationship between the "Struts program each file (2)" http://dev.9cbs.net/develop/Article/29/29133.shtm
"How to implement Struts database application (1) http://dev.9cbs.net/develop/Article/29/29151.shtm
"How to implement Struts database applications (2)" http://dev.9cbs.net/develop/Article/29/29138.shtm
"How to implement pagination display in the Struts database application (1)" http://dev.9cbs.net/develop/Article/29/29139.shtm
"How to implement pagination display in the Struts database application (2)" http://dev.9cbs.net/develop/Article/29/29140.shtm
"How to implement records in the Struts database application" http://dev.9cbs.net/develop/Article/29/29219.SHTM
"How to implement records in the Struts database application (continued)" http://dev.9cbs.net/develop/Article/29/29222.shtm
"How to implement records in the Struts database application"
"How to build a Struts database application with landing page"
"How to build a Struts database application with landing page and role"
The above example development environment: Java Web Studio Series Development Environment Visual Strutst version.
The latest JavaWebStudio download address: ftp: //210.36.64.79/kui
The above example source program download address: ftp: //210.36.64.79/kui
Key Tip: The setting of the JSPOUT property page is that this example is different from the steps in "How to Implement Struts Database Application", which is the core content of this example. What we have to do is added to the "Record Operation" selection item in the "Record Operation" selection item in the setting of the JSPOUT property page.
[the goal]
The goal of this example is to implement a simple Struts database application. Its function is to read data from SQL Server 2000 and displayed in the output page in the form of a table.
Define a field named "Test" table:
Enter some test data:
[effect]
Add a new record page:
Select "Add New Record":
If you run dblist.jsp, choose all display, and go to the last page, you can see the new record just added:
The recording of the serial number is 20 is the last addition, and the number of serial numbers is 21 is just added. [background knowledge]
[step]
In addition to the steps in the Struts Database Application, this example is except for the Struts Database Application File Wizard, other steps are exactly the same, so the same steps details "How to implement the struts database application".
1. Open the Visual Struts development environment:
Start JavaWebStudio.exe files from the desktop JavaWebstudio fast or bin directory launched the Visual Struts development environment of JavaWebStudio.
2. Create an "empty Struts database application template application" application:
Select the menu "File" - "New" - "New Project", pop up the new project dialog, as shown in Figure 3-1:
Select "Empty Struts Database Application Template" in the dialog box, enter "DBAPP", Package (Package Name) and location in the project name, using the default value, and certainly can be changed as needed. Finally, click the "OK" button to complete the establishment of the new project.
In the root of the DBAPP project, you contain four subdirectories and two files, which is the standard structure of the JSPStudio project, it is best not to change their default names, otherwise there will be problems.
3. Use the Struts Database Application File Wizard to establish a new application:
At the JSPStudio file manager, click the right mouse button. In the pop-up menu, select "Struts Database Application File Wizard" into the Struts File Wizard dialog, or select the menu "file" - "New" - "Struts Database Application File Wizard" The Struts File Wizard dialog box.
Enter the "DBList" file name in the filename input bar under the Struts file wizard dialog jsp file, and other files use the default settings.
(1) Enter the file name:
(2) Import the field information of the SQL statement and the data table from the data source (field name, and field type):
(3) Select the desired table "Test" from the data table.
It is important to note that the "Field information of the SQL statement and data table from the data source" and "Select the table from the data table" is merely generated to automatically generate SQL statements and read field information, here Complete can be manually entered directly, unrelated to the configuration of the database connection pool, below, and then configure the database connection pool separately.
Next, configure the database connection pool, and other property pages can be used by default, and the data connection configuration property page is directly turned directly.
(4) JSPOUT property page settings:
The setting of the JSPOUT property page is the only step in the "How to Implement Struts Database Application", which is the core content of this example. As can be seen from the figure, we have to do it just to add the "Record Operation" selection in the settings of the "Record Operation" selection item.
(5) Configure the database connection pool:
(Omit)
4, project file structure
Project directory structure analysis See "How to achieve the simplest struts program", this Struts database application file wizard automatically generates six files, where the web directory is input, output two JSP files, the SRC directory is a Java file. All program source code is automatically generated by the file wizard except that the file name is automatically generated, and all configurations are also automatically completed.
Refresh the JSPSTUDIO file manager, then discover three files automatically in the web directory, which is dblist.jsp and dblist.jsp and dblistinsert.jsp, the former is an input JSP file, the middle is output JSP file, the latter is adding a record The page file; the SRC / EMPTYPRJ directory automatically generates four files, which are dblist action.java, dblist form.java, the former is an action file, the latter is a formaction file; and the database operation file dblist.java and dblistdao. Java, the former is used to save the bean recorded by the data table, and the latter is a database operation DAO file. [Special Tips] This example is more than a file dblistinsert.jsp compared to the example of "How to Remove Record, Update and Link" in the Struts Database Application.
If the data is selected, SQL Server 2000, you need to put the following code in the DAO file:
// Please join the down with SQL Server:
//con.setautoCommit (true);
// SQL Server
Both rewritten into the following code:
// Please join the down with SQL Server:
Con.SetAutocommit (True); // Note !! This is this line, it turned out to be annotated, now you have to get your annotation !!
// SQL Server
Through the above rewriting, the SQL Server 2000 can be recorded, deleted, and adding the SQL Server 2000 by JDBC.
5, compile, start the server, run:
By compiling the project and start the server, then the DBList.jsp runs DBList.jsp, and runs DBListInsert.jsp through the "Run" button on the toolbar, and enter the corresponding data:
Select "Add New Record":
If you run dblist.jsp, choose all display, and go to the last page, you can see the new record just added:
Through the above steps, the estimated target function is achieved.
[