This article shares form form writing technology for your reference. The specific content is as follows
Write back to support Java spelling js method:
/** * Write back form* * @param mRequest * @return */ public static String writeBackMapToForm(Map mRequest) { return writeBackMapToForm(mRequest, new String[]{}, "writeBackMapToForm"); } /** * Write back form* * @param mRequest * @param ignoreName Define which key values input does not write back* @return */ public static String writeBackMapToForm(Map mRequest, String[] ignoreName, String jsFunctionName) { mRequest.remove("checkbox_template"); //Do not write back the value of checkbox in the list StringBuffer rtValue = new StringBuffer(); rtValue.append(" var mForm = new Object();/n"); rtValue.append(" var indexArray = new Array();/n"); rtValue.append(" function writeBackMapToForm() {/n"); Iterator itMRequest = mRequest.keySet().iterator(); while (itMRequest.hasNext()) { String tempKey = (String) itMRequest.next(); Object tempValue = mRequest.get(tempKey); if (tempKey.startsWith("VENUS") || tempKey.startsWith("RANMIN")) { continue; } if (RmStringHelper.ArrayContainString(ignoreName, tempKey)) { continue; } String tempValueNew = ""; if (tempValue instanceof String) { //If it is a single value, directly inject tempValueNew = RmStringHelper.replaceStringToScript((String)tempValue); //After taking it out from the database, you need to convert rtValue.append(" indexArray[indexArray.length] = /"" + tempKey + "/";/n"); rtValue.append(" mForm[/"" + tempKey + "/"] = /"" + tempValueNew + "/";/n"); } else if (tempValue instanceof String[]) { //If it is a multi-value, put into the array 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 + "/"] = ["); for (int i = 0; i < myArray.length; i++) { if (i > 0) rtValue.append(","); tempValueNew = RmStringHelper.replaceStringToScript(myArray[i]); rtValue.append("/"" + tempValueNew + "/""); } rtValue.append("];/n"); } } else if (tempValue instanceof Timestamp) { //If it is a timestamp, directly inject if(tempValue == null) { continue; } tempValueNew = RmStringHelper.replaceStringToScript(tempValue.toString().substring(0,19)); rtValue.append(" indexArray[indexArray.length] = /"" + tempKey + "/";/n"); rtValue.append(" mForm[/"" + tempKey + "/"] = /"" + tempValueNew + "/";/n"); } else if (tempValue instanceof BigDecimal){ tempValueNew = RmStringHelper.replaceStringToScript(tempValue.toString()); rtValue.append(" indexArray[indexArray.length] = /"" + tempKey + "/";/n"); rtValue.append(" mForm[/"" + tempKey + "/"] = /"" + tempValueNew + "/";/n"); } else { if(tempValue != null) { RmStringHelper.log("When writing back the page, I encountered an unknown java type:" + tempValue); } continue; } } rtValue.append(" for(var i=0; i<indexArray.length; i++) {/n"); rtValue.append(" writeBackValue(indexArray[i]);/n"); rtValue.append(" }/n"); rtValue.append(" }/n"); rtValue.append(jsFunctionName + "();/n"); return rtValue.toString(); }//Use this method to put the value in the request into the mForm object var mForm = new Object(); var indexArray = new Array(); function 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] = "owner_id"; mForm["owner_id"] = "s1"; for(var i=0; i<indexArray.length; i++) { writeBackValue(indexArray[i]); } }writeBackMapToForm(); The output calls the js method after adding the key statement jsp page: <script language="javascript"><% //Form writeback if(request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES) != null) { //If the form writeback bean retrieved in the request is not empty out.print(RmVoHelper.writeBackMapToForm((java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES))); //The script for outputting the form writeback method} Map mapt = (java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES); System.out.print("infois:"+mapt.entrySet()); out.print("alert(1);");%></script> //The js format content actually injected by the above statement is as follows: var mForm = new Object(); var indexArray = new Array(); function writeBackMapToForm() { indexArray[indexArray.length] = "_function_id_"; mForm["_function_id_"] = "367021250000000000050"; indexArray[indexArray.length] = "cmd"; mForm["cmd"] = "listBusinessTypePage"; for(var i=0; i<indexArray.length; i++) { writeBackValue(indexArray[i]); } }writeBackMapToForm(); //After injection, call the js writeback form method function writeBackValue(inputName) { if(form.elements[inputName] == undefined) { return false;}if(form.elements[inputName].value != undefined) { form.elements[inputName].value = mForm[inputName]; } if(form.elements[inputName].length != undefined ) { var thisValue = mForm[inputName]; if(mForm[inputName][0] == undefined) { thisValue = new Array(); thisValue[thisValue.length] = mForm[inputName]; } if(form.elements[inputName].length != null) { var tempLength = form.elements[inputName].length; for(var j=0; j<tempLength; j++) { var thisObj = form.elements[inputName][j]; for(var k=0; k<thisValue.length; k++) { if( thisObj.value == thisValue[k]) { if( thisObj.checked != undefined) { thisObj.checked = true; break; } else if( thisObj.selected != undefined) { thisObj.selected = true; break; } } else { if( thisObj.checked != undefined) { thisObj.checked = false; } else if( thisObj.selected != undefined) { thisObj.selected = false; } } } } } } } } }The above is all about this article, I hope it will be helpful to everyone's learning.