最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

form表單回寫技術(shù)java實(shí)現(xiàn)

 更新時(shí)間:2016年04月26日 17:07:17   作者:BeGit  
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)form表單回寫技術(shù)的相關(guān)資料,需要的朋友可以參考下

本文實(shí)例為大家分享了form表單回寫技術(shù),供大家參考,具體內(nèi)容如下

回寫支持的java拼js的方法:

 /**
   * 回寫表單
   *
   * @param mRequest
   * @return
   */
  public static String writeBackMapToForm(Map mRequest) {
    return writeBackMapToForm(mRequest, new String[]{}, "writeBackMapToForm");
  }
  /**
   * 回寫表單
   *
   * @param mRequest
   * @param ignoreName 定義哪些key值的input不回寫
   * @return
   */
  public static String writeBackMapToForm(Map mRequest, String[] ignoreName, String jsFunctionName) {
  mRequest.remove("checkbox_template"); //不回寫列表中checkbox的值
    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) { //如果是單值,直接注入
        tempValueNew = RmStringHelper.replaceStringToScript((String)tempValue); //從數(shù)據(jù)庫中取出來以后需要轉(zhuǎn)換1次
        rtValue.append("  indexArray[indexArray.length] = \"" + tempKey + "\";\n");
        rtValue.append("  mForm[\"" + tempKey + "\"] = \"" + tempValueNew + "\";\n");
      } else if (tempValue instanceof String[]) { //如果是多值,放入數(shù)組
        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) { //如果是時(shí)間戳,直接注入
        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("在回寫頁面時(shí),遇到了未知java類型:" + 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();
  }
//通過此方法將request中的值放入mForm對象中
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();
 
關(guān)鍵語句jsp頁面中加入后輸出調(diào)用js方法:
 
<script language="javascript">
<% //表單回寫
  if(request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES) != null) { //如果request中取出的表單回寫bean不為空
    out.print(RmVoHelper.writeBackMapToForm((java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES))); //輸出表單回寫方法的腳本
  }
 Map mapt = (java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES);
 System.out.print("infois:"+mapt.entrySet());
 out.print("alert(1);");
%>
</script>
 
//上面語句實(shí)際上注入的js格式內(nèi)容如:
var mForm = new Object();
 var indexArray = new Array();
 function writeBackMapToForm() {
  indexArray[indexArray.length] = "_function_id_";
  mForm["_function_id_"] = "3670212500000000050";
  indexArray[indexArray.length] = "cmd";
  mForm["cmd"] = "listBusinessTypePage";
  for(var i=0; i<indexArray.length; i++) {
   writeBackValue(indexArray[i]);
  }
 }
writeBackMapToForm();
 
  
 
 
 
//注入后調(diào)用js回寫表單方法
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;                
            }  
          }
        }
      }
    }  
           
  }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。

相關(guān)文章

  • 解決@JsonIgnore的使用以及自己踩坑

    解決@JsonIgnore的使用以及自己踩坑

    這篇文章主要介紹了解決@JsonIgnore的使用以及自己踩坑,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • SpringBoot結(jié)果封裝和異常攔截的實(shí)現(xiàn)示例

    SpringBoot結(jié)果封裝和異常攔截的實(shí)現(xiàn)示例

    SpringBoot 項(xiàng)目中,我們通常需要將結(jié)果數(shù)據(jù)封裝成特定的格式,以方便客戶端進(jìn)行處理,本文主要介紹了SpringBoot?優(yōu)雅的結(jié)果封裝和異常攔截,感興趣的可以了解一下
    2023-08-08
  • spring data jpa 查詢自定義字段,轉(zhuǎn)換為自定義實(shí)體方式

    spring data jpa 查詢自定義字段,轉(zhuǎn)換為自定義實(shí)體方式

    這篇文章主要介紹了spring data jpa 查詢自定義字段,轉(zhuǎn)換為自定義實(shí)體方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • java數(shù)據(jù)結(jié)構(gòu)基礎(chǔ):單鏈表與雙向鏈表

    java數(shù)據(jù)結(jié)構(gòu)基礎(chǔ):單鏈表與雙向鏈表

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)單鏈表、雙向鏈表的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • SpringBoot從2.7.x 升級到3.3注意事項(xiàng)

    SpringBoot從2.7.x 升級到3.3注意事項(xiàng)

    從SpringBoot 2.7.x升級到3.3涉及多個(gè)重要變更,特別是因?yàn)?nbsp;Spring Boot 3.x 系列基于 Jakarta EE 9,而不再使用 Java EE,本文就來詳細(xì)的介紹一下,感興趣的可以了解一下
    2024-09-09
  • SpringBoot集成MinIO的示例代碼

    SpringBoot集成MinIO的示例代碼

    對象存儲服務(wù)OSS是一種海量、安全、低成本、高可靠的云存儲服務(wù),適合存放任意類型的文件,這篇文章主要介紹了SpringBoot集成MinIO的示例代碼,需要的朋友可以參考下
    2023-06-06
  • 利用Java搭建個(gè)簡單的Netty通信實(shí)例教程

    利用Java搭建個(gè)簡單的Netty通信實(shí)例教程

    這篇文章主要給大家介紹了關(guān)于如何利用Java搭建個(gè)簡單的Netty通信,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Java具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • Java?深入理解創(chuàng)建型設(shè)計(jì)模式之建造者模式

    Java?深入理解創(chuàng)建型設(shè)計(jì)模式之建造者模式

    建造者(Builder)模式和工廠模式的關(guān)注點(diǎn)不同:建造者模式注重零部件的組裝過程,而工廠方法模式更注重零部件的創(chuàng)建過程,但兩者可以結(jié)合使用
    2022-02-02
  • SpringBoot整合Hashids實(shí)現(xiàn)數(shù)據(jù)ID加密隱藏的全過程

    SpringBoot整合Hashids實(shí)現(xiàn)數(shù)據(jù)ID加密隱藏的全過程

    這篇文章主要為大家詳細(xì)介紹了SpringBoot整合Hashids實(shí)現(xiàn)數(shù)據(jù)ID加密隱藏的全過程,文中的示例代碼講解詳細(xì),對大家的學(xué)習(xí)或工作有一定的幫助,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-01-01
  • Java基礎(chǔ)之ArrayList的擴(kuò)容機(jī)制

    Java基礎(chǔ)之ArrayList的擴(kuò)容機(jī)制

    這篇文章主要介紹了Java基礎(chǔ)之ArrayList的擴(kuò)容機(jī)制,文中有非常詳細(xì)的代碼示例,對正在學(xué)習(xí)java基礎(chǔ)的小伙伴們有很好的幫助,需要的朋友可以參考下
    2021-05-05

最新評論

宝丰县| 额尔古纳市| 稻城县| 永新县| 永和县| 囊谦县| 浏阳市| 安新县| 雷山县| 弋阳县| 泰来县| 东辽县| 鲁甸县| 峡江县| 蚌埠市| 五峰| 萍乡市| 庆阳市| 沾化县| 陈巴尔虎旗| 昌图县| 秭归县| 吉水县| 儋州市| 思南县| 闵行区| 浦江县| 连城县| 静海县| 孙吴县| 新晃| 灵宝市| 宜黄县| 长武县| 南木林县| 红桥区| 禄丰县| 西充县| 黄山市| 德清县| 碌曲县|