How to implement recording deletion, update, and links in the Struts database application

zhaozj2021-02-16  46

How to implement recording deletion, update, and links 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, updates, and links in Struts database applications"

"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 only the deletion, update, and links of the recorded record in the "Record Operation" selection in the settings 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]

Enter the page (select "All Display"):

Output page:

Select the "Edit" function and edit the data in the table:

update record:

[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 are only doing the deletion, update, and links of the recorded record in the "Record Operation" selection item in the settings of the JSPOUT page.

(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 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.

[Special Tip] If the data is selected, SQL Server 2000 is selected, you need to put the following code in the DAO file:

// Please join the downlink 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:

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:

Next, try the "Edit" function:

Next is to implement the data within the table in the table:

Next is to implement the "Update" function:

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

[Program source code]

For program source code, this example is unique to the program source code in "How to Implement Struts Database Application" is a dblistout.jsp file. Different are deleted, editing, updating, and paging features in the table, as follows:

Other files are identical, the next page is dblistout.jsp file source code:

<% @ page contenttype = "text / html; charset = GB2312" Language = "java"%>

<% @ Taglib URI = "/

Web

-

Inf

/struts-bean.tld "prefix =" bean "%>

<% @ Taglib URI = "/

Web

-

Inf

/struts-html.tld "prefix =" html "%>

<% @ Taglib URI = "/

Web

-

Inf

/struts-logic.tld "prefix =" Logic "%>

<% @ Taglib URI = "/

Web

-

Inf

/struts-template.tld "prefix =" Template "%>

</ title></p> <p><HTML: BASE /></p> <p></ hEAD></p> <p><body bgcolor = "white"></p> <p><table width = "98%" border = "1" bgcolor = "# e6f2e7"</p> <p>Bordercolordark = "# ffffff" bordercolorlight = "# 008000" Cellpadding = "3" cellspacing = "0"> <tr bgcolor = '# 90c090'></p> <p><TD> <span contentteditable = true> Sequence number </ span> </ td></p> <p><TD> <span contenttedITable = true> Name </ span> </ td></p> <p><TD> <span contentteditable = true> Remarks </ span> </ td></p> <p><TD> <span contentteditable = true> Delete </ span> </ td></p> <p><TD> <span contentteditable = true> Editing </ span> </ td></p> <p><TD> <span contentable = true> Link </ span> </ td></p> <p></ TR></p> <p><logic: Itereate Name = 'dblist' id = 'dblist' type = 'emptyprj.dblist' scope = 'request'></p> <p><logic: Notequal name = 'dblistform' proteTy = 'action' value = 'edit'></p> <p><tr></p> <p><TD> <bean: Write Name = 'dblist' proteTy = 'serial number' /> </ td></p> <p><TD> <bean: Write Name = 'dblist' Property = 'Name' /> </ TD></p> <p><TD> <bean: Write Name = 'dblist' Property = 'Note' /> </ td></p> <p><TD> <a href = "dblistAction.do?action=delete&search=search&pression=</p> <p><bean: write name = 'dblist' print = 'serial number' />> Delete </A> </ TD></p> <p><TD> <a href = "dblistAction.do?action=edit&search=search&pression=</p> <p><bean: write name = 'dblist' print = 'serial number' />> Edit </a> </ td></p> <p><TD> <a href = "dblistAction.do?action=Link&search=search&pression=</p> <p><bean: Write Name = 'dblist' Property = 'Serial' />>> Link </a> </ td> </ tr></p> <p></ logic: Notequal></p> <p><logic: equal name = 'dblistform' protety = 'action' value = 'edit'></p> <p><tr></p> <p><form method = 'pos' name = 'dblistform' action =</p> <p>"/DBAPP/DblistAction.do?action=update&search=search&pression=</p> <p><bean: Write Name = 'DBLIST' Property = 'Serial' />>>></p> <p><TD> <HTML: Text Name = 'dblist' Property = 'Serial' /> </ TD></p> <p><TD> <HTML: Text Name = 'dblist' Property = 'Name' /> </ TD></p> <p><TD> <HTML: Text Name = 'dblist' Property = 'Note' /> </ TD></p> <p><TD> <a href = "dblistAction.do?action=delete&search=search&pression=</p> <p><bean: write name = 'dblist' print = 'serial number' />> Delete </A> </ TD></p> <p><TD> <HTML: Submit value = 'Update'> </ html: submit> </ form></p> <p><form method = 'post' action = "dblistaction.do?action=reset&search=search&pression=</p> <p><bean: Write Name = 'DBLIST' Property = 'Serial' />> <html: Submit Value = 'Cancel'> </ html: Submit></p> <p></ form> </ td></p> <p><TD> <a href = "dblistAction.do?action=Link&search=search&pression=</p> <p><bean: Write Name = 'DBList' Property = 'Serial' />> Link </a> </ TD></p> <p></ TR></p> <p></ logic: Equal></p> <p></ logic: Iterate></p> <p><TR> <TD align = middle colSpan = 7> <bean: write proty = 'pageStr' name = 'dblistform' filter = 'false' /> </ td> </ tr> </ tr></p> <p></ TABLE></p> <p></ body></p> <p></ html: html></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-25852.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="25852" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.049</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'x390HopOP8LCGCez4POxavFZAz_2BrMoH4XoCQQzwmDtZbT_2FwK5T3pE0d4yWgZBalQggoEEIclXUupx1A1F2LzJg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>