How to implement Struts database applications

zhaozj2021-02-16  47

How to implement Struts database applications

[Related Links] "JavaWebStudio Series Development Tools Visaul Struts Report" http://dev.9cbs.net/develop/Article/28/28871.shtm "How to achieve the simplest struts program" http: //dev.9cbs. Net / development / article / 28 / 28946.SHTM "Struts drop-down box" http://dev.9cbs.net/develop/Article/28/28956.SHTM "http: // dev" http: // dev .9cbs.net / development / article / 29 / 29042.shtm "Struts check box" http://dev.9cbs.net/develop/Article/29/29043 The relationship between the SHTM "Struts program (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 the struts database application (1)" http://dev.9cbs.net/develop/Article/29/29135.shtm "How to implement the Struts database application (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 paging display (2) "" How to implement record in the Struts database application "in the Struts database application" "How to add a record in the Struts database application" "How to build a landing Page Struts Database Application "How to create 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

Note: How to implement Struts database applications (1) "

http://dev.9cbs.net/develop/Article/29/29135.SHTM did not publish this article, so relealed this article.

[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]

(1) All shows:

Enter the page:

Output page:

(2) Query display:

[background knowledge]

[step]

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. As you can see from the file manager, the file structure of the DBAPP project is as follows:

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. As shown below:

(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) Configure the database connection pool:

This example only uses a system default variable MyBeanVariable1, and it saves the input data.

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 two files automatically in the web directory, which is dblist.jsp and dblist.jsp, the former is an input JSP file, the latter is an output JSP file; SRC / EMPTYPRJ directory automatically generated Four files, are dblist action.java and dblist form.java, the former is an action file, the latter is a formaction file; there is a database operation file dblist.java and dblistdao.java, the former is used to save data table recorded Bean The latter is a database operation DAO file.

DBList.jsp file:

DBListOut.jsp file:

5, compile, start the server, run:

Compile the project and start the server separately by the button on the toolbar, then the dblist.jsp runs dblist.jsp by the "Run" button on the toolbar:

First try all the display functions, click the "All Display" button, if shown in the following figure:

One to try the lookup function, enter the number 3 in the text box, click the "Find" button, if shown in the following picture:

Through the above steps, the estimated target function is achieved.

[Program source code]

DBList.jsp file:

DBListOut.jsp file:

DBList.java file: This defines a bean for saving data table data, its variables are completely corresponding to the fields of the database table, that is, the fields that the SQL statement in the Database Application File Wizard To completely correspond.

DBListDao.java file:

Here, a DAO class is defined to implement functions such as data plus, delete, update, add, and generate zone strings.

DBListAction.java file:

Here, an Action class is defined to implement the forwarding function of the page, and additional operations of different request types are also included. The Action variable represents an operation type, which is equivalent to the event type. Through this variable, it has achieved similar.

Net

The function of "event drive".

Package EmptyPRJ;

Web.xml file:

Here, in addition to the general Struts project configuration, it includes the configuration of the database connection pool, see the code of the dark body part.

Struts-config.xml file:

In addition, the project also includes the implementation file of the database connection pool ConnectionPool.java and the database connection pool, DBINITSERVLET.JAVA. The code for these two files is omitted here. If the reader needs to download Java Web Studio.

转载请注明原文地址:https://www.9cbs.com/read-25853.html

New Post(0)