JSP and SQL Server's message book (transfer)

xiaoxiao2021-03-06  17

<% @ page import = "java.sql. *"%> add message inTo Table </ title> </ head> <body> < % String name = request.getParameter ("name"); string mail = request.getParameter ("mail"); string title = request.getParameter ("Title"); string content = request.getParameter ("content"); if (Name == NULL) Name = ""; if (title == NULL) Title = ""; if (content == NULL) Content = ""; if (mail == null) Mail = ""; if (Name .length () == 0) Out.println ("The name of the message cannot be empty!"); else if (title.length () == 0) Out.println ("message theme can not be empty!"); Else IF (content.length () == 0) Out.println ("message content is not empty!"); else {java.util.date Date = new java.util.date (); string datetime = new timestamp (Date .gettime ()). TOSTRING (); Try {class.forname ("sun.jdbc.odbc.jdbcodbcdriver); string url =" jdbc: odbc: user_db "; connection con = drivermanager.getConnection (URL," Inso " , "Insher"); preparedStatement Stm = Con.PrepareStatement ("Insert Into Message Values ​​(?,?,?,?)"); stm.setstring (1, title); stm.setstring (2, name); IF (mail.length () == 0) stm.setstring (3, null); ELS E stm.setstring (3, mail); stm.setstring (4, datetime); stm.setstring (5, content); try {stm.executeQuery ();} catch (exception e) {}con.close (); } Catch (Exception E) {}%> <jsp: forward page = "view_message.jsp" /> <%}%> </ body> </ html> <! - add_message.jsp - <% @ Page Import = "java.sql. *"%> <html> <head> <title> address message inTo Table <</p> <p>/ Title> </ head> <body> <% string name = request.getParameter ("name"); string mail = request.getParameter ("mail"); string title = request.getParameter ("Title"); string Content = Request.getParameter ("content"); if (name == null) Name = ""; if (title == null) title = ""; if (content == null) content = "; if (mail = = NULL) MAIL = ""; if (name.length () == 0) Out.println ("The name of the message cannot be empty!"); Else IF (title.length () == 0) Out.println "The message theme can not be empty!"); Else IF () == 0) Out.println ("message content is not empty!"); Else {java.util.date Date = new java.util. Date (); string datetime = new timestamp (Date.getTime ()). TOSTRING (); try {class.forname ("sun.jdbc.odbc.jdbcodbcdriver); string url =" jdbc: odbc: user_db "; connection Con = DriverManager.getConnection (URL, "Inso", "Insher"); preparedStatement Stm = Con.PrepareStatement ("Insert Into Message Values ​​(?,?,?,?,?)"; stm.setstring (1, Title ); stm.setstring (2, name); if (mail.length () == 0) stm.setstring (3, null); else stm.setstring (3, mail); stm.setstring (4, datetime); Stm.setstring (5, content); try {stm.executeQuery ();} catch (exception e) {} con.close ();} catch (exception e) {}%> <jsp: forward page = "view_message.jsp" /> <%}%> </ body> < / html> <! - index.html -> <html> <head> <title> message board </ title> </ head> <body> <table width = "90%" align = "center" border = 1 cellspacing = "0" cellpadding = "0" bordercolordark = "# 88A6DD"</p> <p>Bordercolorlight = "# 88a6dd"> <tr> <td align = "center" BGColor = "# 8886dd"> Visitor message board </ td> <TR> <TR> <TD> <table align = "center" border = 1 cellspacing = "0" cellpadding = "0" bordercolordark = "# 888a6dd" bordercolorlight = "# 888a6dd"> <form action = "add_message.jsp"> <TD> <TD> Name: </ td> <td bgcolor = "# 88a6dd"> <input type = "text" name = "name" size = 25> <td> </ tr> <tr> <td bgcolor = "# 88a6dd"> e-mail: </ td> < TD BGCOLOR = "# 88a6dd"> <input type = "text" name = "mail" size = 25> <td> <TR> <TD> <TD> topic: </ td> <td bgcolor = "# 88A6DD "> <input type =" name = "title" size = 25> <td> </ tr> <tr> <td value = "top" bgcolor = "# 888a6dd"> message: </ td> <TD> <textarea name = "content" ROWS = 7 COLS = 25> </ TEXTAREA> </ TD> <TD Colspan = 3> <table align = "Width =" 100% "cellspacing =" 0 "cellpadding =" 0 "bordercolordark =" # 88A6DD "bordercolorlight =" # 888a6dd "> <tr> <TD align =" center "bgcolor =" # 88A6dd "> <input type =" submit "value = "Submit Message"> </ TD> <TD Align = "Center"> <a href="view_message.jsp"> <font size = 2> View message </ font> </a> </ td> <td align =</p> <p>"center" bgcolor = "# 88A6DD"> <input type = "reset" value = "Re-filled"> </ td> </ tr> </ table> </ td> </ tr> </ form> </ Table> </ td> </ tr> </ table> </ body> </ html> <html> <head> <title> message board </ title> </ head> <body> <table width = "60 % "align =" center "border = 1 cellspacing =" 0 "cellpadding =" 0 "bordercolordark =" # 88A6DD "bordercolorlight =" # 88A6DD "> <tr> <TD align =" center "BGColor =" # 888a6dd "> Visitor message board </ TD> </ TD> <Table align = "center" border = 1 cellspacing = "0" cellpadding = "0" bordercolordark = "# 88a6dd" bordercolorlight = "# 888a6dd"> <Form action = "add_message.jsp"> <tr> <td> Name: </ td> <td bgcolor = "# 88a6dd"> <input type = "text" name = "name" size = 25> </ td > </ Tr> <tr> <td bgcolor = "# 88A6DD"> E-mail: </ td> <td bgcolor = "# 888a6dd"> <input type = "text" name = "mail" size = 25> </ TD> <TD> Topic: </ TD> <TD BGColor = "# 88A6DD"> <input type = "text" name = "title" size = 25> </ td> < / TR> <TR> <TD VALIGN = "TOP" BGColor = "# 88A6DD"> Message: </ td> <TD> <textarea name = "content" rows = 7 cols = 25> </ textarea> </ td > </ TR> <TR> <</p> <p>TD colspan = 3> <table align = "center" width = "100%" cellspacing = "0" cellpadding = "0" bordercolordark = "# 888a6dd" bordercolorlight = "# 88A6DD"> <tr> <td align = "center "BGCOLOR =" # 88A6DD "> <input type =" submit "value =" Submit Message "> </ td> <TD align =" center "> <a href="view_message.jsp"> <font size = 2> View message </ font> </a> </ td> <td align = "center" bgcolor = "# 888a6dd"> <input type = "reset" value = "Re-filing"> </ td> </ tr> </ Table> </ td> </ tr> </ form> </ table> </ td> </ tr> </ table> </ body> </ html> <! - view_message.jsp -> <% @ page import = "java.sql. *"%> <html> <head> <title> show the message in the table </ title> </ head> <body> <p align = "center"> All Visitors Message </ p> <hr> <% try {class.forname ("sun.jdbc.odbc.jdbcodbcodbdriver); string url =" jdbc: odbc: user_db "; connection con = DriverManager.getConnection (URL," Insher "," insher "); statement stm = con.createstatement (); resultset result = stm.executeQuery (" select count (*) from message "; int message_count = 0; if (Result.next ()) {message_count = Result.Getint (1); result.close ();} if (Message_Count> 0) {result = STM. ExecuteQuery ("Select * from message order by time desc"); while (result.next ()) {string title = result.getstring ("title"); string name = result.getstring ("name"); string mail = Result.getstring ("</p> <p>"); timestamp time = result.gettimestamp (" time "); date date_time = new date (time.gettime ()); time.gettime = new time (Time.getTime ()); string content = result.getstring (" ");%> <table width =" 100% "align =" center "border = 1 cellspacing =" 0 "cellpadding =" 0 "bordercolordark =" # 000000 "Bordercolorlight =" # 888a6dd "> <tr> <TD BGColor = "# 88a6dd"> <font size = 2> topic: </ font> </ td> <TD colspan = 3> <% = title%> </ td> </ tr> <tr> <td bgcolor = "# 88A6DD"> <font size = 2> Messager: </ font> </ td> <TD> <% = Name%> </ TD> <TD BGColor = "# 888a6dd"> <font size = 2> E-mail: </ font> </ td> <td> <% out.println ("<a href = mailto:" "</A>");%> </ td> </ tr> <tr> <td bgcolor = "# 88A6DD"> <font size = 2> Message time: </ font> </ td> <TD colspan = 3> <% out.println ("<font size = 2> " DATE_TIME " TIME_TIME "</ font>");%> <td> </ tr> <tr> <td align = "center> <% out.println (" (" message_count " ) ")");%> </ td> <td colspan = 3> <% = content%> </ td> </ TR> </ table> <% out.println ("<hr>"); message_count-- } result.close (); con.close ();} else {Out.println ("There is currently no message!"); con.close ();}} Catch (Exception E) {OUT.Println (E);}%> <p align = "center"</p> <p>> <a href="../message/index.html"> I want to leave a message </a> </ p> </ body> </ html> <! - view_message.jsp -> <% @Page Import = "java.sql. *"%> <html> <head> <title> show the message in the table </ title> </ head> <body> <p align = "center"> All visitor message </ p > <hr> <% try {class.Forname ("sun.jdbc.odbc.jdbcodbcdriver"); string url = "jdbc: odbc: user_db"; connection con = drivermanager.getConnection (URL, "Inso", "Inso" ); Statement stm = con.createstatement (); resultset result = stm.executequery ("select count (*) from message"); int message_count = 0; if (Result.Next ()) {Message_count = Result.Getint (1 ); result.close ();} if (message_count> 0) {result = stm.executeQuery ("SELECT * from message order by time dec"); while (result.next ()) {string title = result.getstring "Title"); string name = result.getstring ("name"); string mail = result.getstring ("mail"); timestamp time = result.getTimeStamp ("time"); Date Date_time = new date (Time.gettime ()); Time time_time = new time (time.gettime ()); string content = result.getstring ("content");%> <Table width = "100%" Align = "center" border = 1 cellspacing = "0" cellpadding = "0" bordercolordark = "# 000000" Bordercolorlight = "# 888a6dd"> <tr> <td bgcolor = "# 88a6dd"> <font size = 2> theme : </ Font> </ td> <td colspan = 3> <% = title%> </ td> </ tr> <tr> <td bgcolor = "# 88A6DD"> <font size = 2> Message: <</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-41313.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="41313" 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.029</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 = 'Dez_2Bg4qF1UZOtJYWnhLErTpEkRUitZCtMe_2BNe7HVGIw2EX0GlFR3yfGNQvmGm1TcfMFR6O_2F11M_2BMpXGPQLrYxg_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>