A file message this code analysis

xiaoxiao2021-03-06  106

A file message this code analysis

As a website and netizens exchange, the message is undoubtedly the best choice. Here, you will introduce a message of a message implemented with a file system component. This message includes four files. Message This fill in the page - Gform.html Message This Procedure - Gform.jsp Message This Display page --Gbook.jsp also has an automatically generated text file --Gbook.txt.

Message This fill in the page - Gform.html This is a simple HTML file that allows the reader to fill in the message and pass the content to gform.jsp.

It html source code as follows: 329studio message form </ title> </ head> <body background = "body background =" limited border = "1" cellspacing = "0" cellpadding = "4" width = "100%" bgcolor = "# d0d0ec"> <tr> <td align = "center" > <font size = " 2" color = "# 000080"> <b> 329studio's message form </ b> </ font> </ td> </ tr> </ table> <form action = "gform. JSP "Method =" POST "> <table border =" 1 "width =" 100% "> <tr> <td> <font color =" # 000080> Name: </ font> </ td> <td> <input type = "text" name = "name" size = "20"> <td> <font color = "# 000080"> Email: </ font> </ td > <TD> <input type = "text" name = "email" size = "40"> <td> <font color = "# 000080> topic: </ font > </ td> <td> <input type = "text" name = "Subject" size = "60"> <td> </ tr> <tr> <td valign = "top"> <font color = " # 000080> Message: </ font> </ td> <td> <textarea name = "MEMO" rows = "6" cols = "60"> </ textarea> </ td> </ tr> </ table > <div align = "center"> <center> <Table Width = "100%"> <trilign = "center"> <td> <</p> <p>Input type = "submit" name = "send" value = "submit message"> </ td> <td> <a href="gbook.jsp"> Browse message </a> </ td> <TD> <input TYPE = "reset" value = "Clear Rewrite"> </ td> </ tr> </ table> </ center> </ div> </ form> </ body> </ html> message processing script - Gform.jsp works the workflow of this script: accepting the data submitted by gform.html, first judge whether it is legal, if legal, turn it into a needed form, then save it in the text file GBOOK.TXT, final redirect to GBOOK .jsp, display all messages, give error tips if it is not legal.</p> <p>The code is as follows: <% @ Page ContentType = "text / html"%> <% @ page language = "java"%> <% @ page import = "java.io. *"%> <% @ Page import = "java .util. * "%> <% @ page import =" java.text. * "%> <%! // Resolve Chinese Display problem public string getstr (string str) {Try {string temp_p = str; byte [] TEMP_T = TEMP_P.GETBYTES ("ISO8859_1"); string temp = new string (TEMP_T); RETURN TEMP;} Catch (Exception E) {} Return "Empty";}%> <% string name; string email; string subject; string Memo; // Read the data name = request.getParameter ("name"); email = request.getParameter ("subject"); memory = request.getParameter ("Subject"); memo = request.getParameter "MEMO"); name.trim (); email.trim (); subject.trim (); memo.trim (); // Check if each input box is input with data IF ((Name.length () == 0 ) || (Email.Length () == 0) || (Subject.Length () == 0) || (Memo.Length () == 0)) {Out.println ("The input box cannot be blank! "); OUT.PRINTLN (" <BRINTLN); OUT.PRINTLN ("<a href=gform.html> Returns </A>"); // No longer processes the following program return;} // first The line contains "name" and "email" String line1; line1 = "message:" Name; line1 = line1 "; // Insert 5 Chinese character space email =" <a href = mailto: " email " > " Email " </a> "; line1 = line1 " EMAI L " email " <br> "; // Second line String line2; line2 =" topic: " Subject " <br> "; // Third behavior" message ", first message / n conversion Become a carriage return <br> String makecontent = new string (); StringTokenizer Strtoken = New StringTokenizer (MEMO, "/ N"); while (STRTOKEN.HASMORETOKENS ()) {MakeContent =</p> <p>Makecontent "<br>" strtoken.nextToken ();} memo = makecontent; // In order to display different background colors, the table output String line3; line3 = "<Table Border = 0 bgcolor = # 00ffff> <TR> < TD> "; line3 = line3 MEMO " </ td> </ tr> </ table> "; // fourth behavior message time string line4; Date currtime = new date (); SimpleDateFormat Formatter = new SimpleDateFormat (" YYYY / MM / DD A HH: MM: SS ", LOCALE.US); line4 =" Time: " formatter.format (currtime);%> <% // write message content write file // first establish a FileWriter instance Try {string path = "c: //tomcat/webapps/myweb/gbook.txt"; FileWriter file = new filewriter (path, true); PrintWriter PWout = New PrintWriter (file); // Write Accessor Message PWout. Println (getStr (line1)); pwout.println (getStr (line2)); PWout.Println; PWout.Println (GetStr (line4)); PWout.Println ("<hr>"); PWOUT .close ();} catch (ioException e) {output (e.tostring ());} // Redirect web page to "Browse Message" GBOOK.JSPRESPONSE.SENDIRECT ("http: //127.0. 0.1: 8080 / myWeb / GBOOK.JSP ");%> Message This display page --Gbook.jsp It is used to display all messages, where we use the file containing statements, making the message become unusual, it is actually benefited The result of the message is written to the message of the message, which writes the format page into the GBook.txt file so that the format is required in GBOOK.JSP.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-101221.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="101221" 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.042</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 = 'SR_2Bj7RW1SwLHMxxnHetz1Kqeuq1TEQUOhl40jb74YzNoTY7luptiU6VKBzrK32WOFClDyAJ1q60ED0CZb2Ua3w_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>