JSP + Javabean step-by-step tutorial (6)

xiaoxiao2021-03-05  43

This section involves two pages, a donewuser.jsp file to implement a record to add actions, another file listuser.jsp file

Used to display all registered user information. Both the two pages involve the specific call of JavaBean, or to see the file,

For key code in the file, you will add a comment to make it easier for you.

DONEWUSER.JSP file

Description: User Registration Operations page, and displays the corresponding feedback according to the user registration, this page is mainly characterized by using

LYF.Adduser This JavaBean's AddNewuser () method is added to record.

<% @ Page ContentType = "text / html; charset = GB2312"%>

<% response.setheader ("Expires", "0");%>

The correct attribute value, "*" represents the match of all attributes ->

User Add </ Title></p> <p></ hEAD></p> <p><body bgcolor = "# ffebbd"></p> <p><div align = "center"> <center></p> <p><%</p> <p>// Call the checkuser () method of lyf.adduser check if there is a duplicate username</p> <p>// If there is a repetition, the corresponding information is displayed.</p> <p>IF (! adduser.checkuser ())</p> <p>{</p> <p>// Page text output information, using the PrintLn method of the JSP built-in object OUT, equivalent to the response.write method in the ASP</p> <p>Out.println ("Sorry, this username" adduser.getusername () "has been applied, please re-select!");</p> <p>// Return represents return, and it will not perform the following processing when running. The function is equivalent to response.end in the ASP.</p> <p>Return;</p> <p>}</p> <p>%></p> <p><%</p> <p>// If there is no user name repeated problem, call the LYF.AddUser's addNewUser () method to add user data to the database, and</p> <p>Add success in accordance with data adding success No to display the corresponding information</p> <p>IF (adduser.addnewuser ()) {</p> <p>%></p> <p><H2> Add user success!</p> <p><H2> Add user failed, please contact the administrator!</p> <p></ Body></p> <p></ Html></p> <p>Listuser.jsp file</p> <p>Description: The User Information list page is used to display all user information registered, and the data is displayed.</p> <p>In order to facilitate everyone to use, a general paging code is used, if it is JDBC2.0 or more other support</p> <p>The database driver of the Type_Scroll_Insensitive cursor can have a more concise paging method.</p> <p>And the statement similar to the previous JSP page does not explain, representing</p> <p>This page is imported into this class library of java.sql.resultset because the RESULTSET should be declared in the middle of the JSP page;</p> <p>Oracle.jdbc.driver. * Class library is an Oracle-specific JDBC driver that allows the JSP page to operate Oracle's database operations.</p> <p><% @ Page ContentType = "text / html; charset = GB2312"%></p> <p><% response.setheader ("Expires", "0");%></p> <p><% @ Page Import = "java.sql.resultset"%></p> <p><% @ Page Import = "Oracle.jdbc.driver. *"%></p> <p><! - Generate a JavaBean: LYF.DB -></p> <p><jsp: usebean id = "db" class = "lyf.db" scope = "request" /></p> <p><jsp: setproperty name = "db" property = "*" /></p> <p><%</p> <p>Java.lang.string strsql; // sql statement</p> <p>INT INTPAGESIZE; / / One page shows the number of records</p> <p>INT INTROWCOUNT; // Total number of records</p> <p>INT INTPAGECUNT; / / Total number of pages</p> <p>INT INTPAGE; // Waiting page number</p> <p>Java.lang.string strpage;</p> <p>INT I, J, K;</p> <p>/ / Set the number of records displayed</p> <p>INTPAGESIZE = 15;</p> <p>/ / Get the page number to be displayed</p> <p>StrPage = Request.getParameter ("Page");</p> <p>if (strpage == null) {// Indicates that there is no Page in querystring, and the first page is displayed.</p> <p>INTPAGE = 1;</p> <p>}</p> <p>Else {/ converts strings into integers</p> <p>INTPAGE = java.lang.integer.parseint (STRPAGE);</p> <p>IF (INTPAGE <1) INTPAGE = 1;</p> <p>}</p> <p>// Get the total number of records</p> <p>strsql = "SELECT Count (*) from User";</p> <p>ResultSet Result = db.executeQuery (strsql); // Execute SQL statement and acquire results set</p> <p>Result.next (); // When the record is just opened, the pointer is before the first record.</p> <p>introwcount = result.get.Getint (1); result.close (); // Close result set</p> <p>// Mode total page</p> <p>INTPAGECOUNT = (Introwcount INTPAGESIZE-1) / INTPAGESIZE</p> <p>// Adjust the page number to be displayed</p> <p>IF (INTPAGECOUNT) INTPAGE = INTPAGECOUNT</p> <p>strsql = "SELECT * from user order by id";</p> <p>/ / Execute the SQL statement and get the result set</p> <p>Result = db.executeQuery (strsql);</p> <p>// Position the record pointer to the first record of the page to be displayed</p> <p>I = (INTPAGE-1) * INTPAGESIZE;</p> <p>For (j = 0; J</p> <p><html></p> <p><HEAD></p> <p><meta http-equiv = "content-language" content = "zh-cn"></p> <p><meta http-equiv = "content-type" content = "text / html; charSet = GB2312"></p> <p><meta name = "generator" content = "Microsoft FrontPage 3.0"></p> <p><meta name = "progid" Content = "frontpage.editor.document"></p> <p><title> User List </ Title></p> <p></ hEAD></p> <p><body bgcolor = "# ffebbd"></p> <p><div align = "center"> <center></p> <p><table border = "1"</p> <p>Bordercolordark = "# ffffff" bordercolorlight = "# 000000" Cellspacing = "0" height = "22"</p> <p>Width = "100%"></p> <p><tr bgcolor = "# ffebad"></p> <p><TD Height = "1" width = "691" class = "main"></p> <p>Page Page</p> <p><a href = "Listuser.jsp? Page = 0> Home</p> <p><a href = "listuser.jsp? Page ="> Previous</p> <p>Previous page</p> <p><a href = "listuser.jsp? Page ="> Next Page</p> <p>Next page</p> <p><a href = "listuser.jsp? Page ="> Last</p> <p>Book = "main" name = "page" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "</p> <p>TabINDEX = "1"> page <input type = "submit" class = "main" value = "go" name = "b1" TabINDEX = "2"> <table border = "1" width = "100%" cellspacing = "0" bordercolorlight = "# 000000"</p> <p>Bordercolordark = "# fffff" class = "main"></p> <p><tr bgcolor = "# ffebad"></p> <p><TD></p> <p><div align = "left"> User name</p> <p><TD></p> <p><p align = "center"> email</p> <p><TD></p> <p><p align = "center"> homepage</p> <p><TD></p> <p><p align = "center"> registration time</p> <p><TD></p> <p><p align = "center"> Description</p> <p><tr bgcolor = "# ffebad"></p> <p><TD></p> <p><div align = "left"></p> <p><TD> <DIV Align = "Center"></p> <p><TD> <DIV Align = "Center"> <font color = "# 0000cc"></p> <p><TD> <DIV Align = "Center"> <font color = "# ff6666"></p> <p><TD> <div align = "center"> <font color = "# 0000ff"></p> <p></ table></p> <p></ body></p> <p></ html></p> <p>First run the program newuser.jsp file, make user registration, then run the listuser.jsp file to see if</p> <p>Add to the database. For specific JSP files and Class files, please see the reference of the specific JSP server software,</p> <p>One of the simplest methods is to run directly with JBuilder 4.0 because it comes with Tomcat server software.</p> <p>Ok, the introduction of JSP Javabean here is basically ended. Through the above learning, everyone should be how JavaBean</p> <p>It has a basic understanding of the JSP program, and the rest is to apply and play in a specific program.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-34241.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="34241" 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.047</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 = 'O9yXsp7g9EI4YLmZ6SLuAbYMzd9OXReglCIAPp7zacMEgPTTiEWlChIrUrXHASBKsLLi5j9FEu0ENJJykkUObQ_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>