บทความนี้แบ่งปันเทคโนโลยีการเขียนแบบฟอร์มสำหรับการอ้างอิงของคุณ เนื้อหาเฉพาะมีดังนี้
เขียนกลับเพื่อรองรับวิธีการสะกดคำ Java JS:
/ ** * เขียนแบบฟอร์มกลับ * * @param mrequest * @return */ สตริงคงที่สาธารณะ wringbackmaptoform (แผนที่ mrequest) {return writebackmaptoform (mrequest, สตริงใหม่ [] {}, "writebackmaptoform"); } / ** * เขียนแบบฟอร์มกลับ * * @param mrequest * @param ความไม่รู้กำหนดว่าค่าคีย์ใดที่ไม่ได้เขียนกลับ * @return * / สตริงคงที่ public String writeBackMaptoForm (แผนที่ mrequest, สตริง [] ไม่รู้ชื่อสตริง jsfunctionname) // อย่าเขียนกลับค่าของช่องทำเครื่องหมายในรายการ StringBuffer rtvalue = new StringBuffer (); rtvalue.append ("var mform = new Object ();/n"); rtvalue.append ("var indexarray = new Array ();/n"); rtvalue.append ("ฟังก์ชั่น writebackmaptoform () {/n"); ตัววนซ้ำ itMrequest = mrequest.keyset (). iterator (); ในขณะที่ (itmrequest.hasnext ()) {string tempkey = (string) itmrequest.next (); วัตถุ tempvalue = mrequest.get (tempkey); if (tempkey.startswith ("Venus") || tempkey.startswith ("ranmin")) {ดำเนินการต่อ; } if (rmstringhelper.arraycontainstring (ไม่รู้ชื่อ, tempkey)) {ดำเนินการต่อ; } String tempValUenew = ""; if (tempValue instring ของสตริง) {// ถ้าเป็นค่าเดียว, ฉีด tempvaluenew โดยตรง = rmstringhelper.replacestringToScript ((สตริง) tempValue); // หลังจากนำออกจากฐานข้อมูลคุณต้องแปลง rtvalue.append ("indexarray [indexarray.length] =/" " + tempkey +"/";/n"); rtvalue.append ("mform [/" " + tempkey +"/"] =/" " + tempvaluenew +"/";/n"); } อื่นถ้า (tempvalue instring ของสตริง []) {// ถ้ามันเป็นหลายค่าให้ใส่ลงในอาร์เรย์ rtvalue.append ("indexarray [indexarray.length] =/" " + tempkey +"/";/n"); String [] myArray = (String []) TempValue; if (tempkey.equals ("cmd")) {tempvaluenew = rmstringhelper.replacestringToscript (myarray [0]); rtvalue.append ("mform [/" " + tempkey +"/"] =/" " + tempvaluenew +"/";/n"); } else {rtvalue.append ("mform [/" " + tempkey +"/"] = ["); สำหรับ (int i = 0; i <myarray.length; i ++) {ถ้า (i> 0) rtvalue.append (","); tempvaluenew = rmstringhelper.replacestringToscript (myarray [i]); rtvalue.append ("/" " + tempvaluenew +"/""); } rtvalue.append ("];/n"); }} อื่นถ้า (tempvalue instanceof timestamp) {// ถ้าเป็น timestamp, ฉีดโดยตรงถ้า (tempvalue == null) {ดำเนินการต่อ; } tempvaluenew = rmstringhelper.replacestringToscript (tempvalue.toString (). substring (0,19)); rtvalue.append ("indexarray [indexarray.length] =/" " + tempkey +"/";/n"); rtvalue.append ("mform [/" " + tempkey +"/"] =/" " + tempvaluenew +"/";/n"); } อื่นถ้า (tempvalue instanceof bigdecimal) {tempvaluenew = rmstringhelper.replacestringToscript (tempvalue.toString ()); rtvalue.append ("indexarray [indexarray.length] =/" " + tempkey +"/";/n"); rtvalue.append ("mform [/" " + tempkey +"/"] =/" " + tempvaluenew +"/";/n"); } else {ถ้า (tempvalue! = null) {rmstringhelper.log ("เมื่อเขียนหน้ากลับฉันพบประเภท Java ที่ไม่รู้จัก:" + tempvalue); } ดำเนินการต่อ; }} rtvalue.append ("สำหรับ (var i = 0; i <indexarray.length; i ++) {/n"); rtvalue.append ("writebackvalue (indexarray [i]);/n"); rtvalue.append ("}/n"); rtvalue.append ("}/n"); rtvalue.append (jsfunctionName + "();/n"); ส่งคืน rtvalue.toString (); } // ใช้วิธีนี้เพื่อใส่ค่าในการร้องขอลงในวัตถุ mform var mform = new Object (); var indexarray = new Array (); ฟังก์ชัน writebackmaptoform () {indexarray [indexarray.length] = "att_id"; mform ["att_id"] = ""; indexarray [indexarray.length] = "BusinessTypeoid"; mform ["BusinessTypeoid"] = [""]; indexarray [indexarray.length] = "Business_type1"; mform ["Business_type1"] = ""; indexarray [indexarray.length] = "Business_type2"; mform ["Business_type2"] = "1"; indexarray [indexarray.length] = "cmd"; mform ["cmd"] = "saveexaminerule"; indexarray [indexarray.length] = "document_content"; mform ["document_content"] = "S2"; indexarray [indexarray.length] = "file_path"; mform ["file_path"] = ""; indexarray [indexarray.length] = "file_template"; mform ["file_template"] = ""; indexarray [indexarray.length] = "gxl"; mform ["gxl"] = "null"; indexarray [indexarray.length] = "ownow_id"; mform ["ownow_id"] = "S1"; สำหรับ (var i = 0; i <indexarray.length; i ++) {writebackvalue (indexarray [i]); }} writebackMaptoform (); เอาท์พุทเรียกเมธอด JS หลังจากเพิ่มคีย์คำสั่ง JSP หน้า: <ภาษาสคริปต์ = "JavaScript"> <% // ฟอร์ม writeback ถ้า (request.getAttribute (RuleeExamineconstants.request_write_back_form_values)! = null) {// out.print (rmvohelper.writebackmaptoform ((java.util.map) request.getAttribute (Ruleexamineconstants.request_write_back_form_values))); // สคริปต์สำหรับการส่งออกวิธีการเขียนแบบฟอร์ม} แผนที่ mapt = (java.util.map) request.getAttribute (RuleeExamineconstants.Request_Write_Back_Form_Values); System.out.print ("infois:"+mapt.entryset ()); out.print ("การแจ้งเตือน (1);");%> </script> // เนื้อหารูปแบบ JS ที่ถูกฉีดโดยคำสั่งข้างต้นเป็นดังนี้: var mform = new Object (); var indexarray = new Array (); ฟังก์ชัน writebackmaptoform () {indexarray [indexarray.length] = "_function_id_"; mform ["_ function_id_"] = "36702125000000000000050"; indexarray [indexarray.length] = "cmd"; mform ["cmd"] = "listbusinesstypepage"; สำหรับ (var i = 0; i <indexarray.length; i ++) {writebackvalue (indexarray [i]); }} writebackMaptoform (); // หลังการฉีดให้โทรหาวิธีการฟอร์มวิธีการเขียน js writeback form method writebackValue (inputName) {if (form.elements [inputName] == undefined) {return false;} ถ้า (form.elements [inputName] .value! = undefined) {form.elements } if (form.elements [inputName] .length! = undefined) {var thisvalue = mform [inputName]; if (mform [inputName] [0] == undefined) {thisValue = new Array (); ค่านี้ [thisvalue.length] = mform [inputname]; } if (form.elements [inputName] .length! = null) {var templength = form.elements [inputName] .length; สำหรับ (var j = 0; j <templength; j ++) {var thisobj = form.elements [inputName] [j]; สำหรับ (var k = 0; k <thisvalue.length; k ++) {ถ้า (thisobj.value == thisvalue [k]) {ถ้า (thisobj.checked! = undefined) {thisobj.checked = true; หยุดพัก; } อื่นถ้า (thisobj.seleescted! = undefined) {thisobj.selected = true; หยุดพัก; }} else {ถ้า (thisobj.checked! = undefined) {thisobj.checked = false; } อื่นถ้า (thisObj.Selected! = undefined) {thisObj.seleesction = false; -ข้างต้นเป็นเรื่องเกี่ยวกับบทความนี้ฉันหวังว่ามันจะเป็นประโยชน์กับการเรียนรู้ของทุกคน