欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

回寫(xiě)支持的java拼js的方法:

 /**
   * 回寫(xiě)表單
   *
   * @param mRequest
   * @return
   */
  public static String writeBackMapToForm(Map mRequest) {
    return writeBackMapToForm(mRequest, new String[]{}, "writeBackMapToForm");
  }
  /**
   * 回寫(xiě)表單
   *
   * @param mRequest
   * @param ignoreName 定義哪些key值的input不回寫(xiě)
   * @return
   */
  public static String writeBackMapToForm(Map mRequest, String[] ignoreName, String jsFunctionName) {
  mRequest.remove("checkbox_template"); //不回寫(xiě)列表中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ù)庫(kù)中取出來(lái)以后需要轉(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("在回寫(xiě)頁(yè)面時(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();
  }
//通過(guò)此方法將request中的值放入mForm對(duì)象中
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)鍵語(yǔ)句jsp頁(yè)面中加入后輸出調(diào)用js方法:
 
<script language="javascript">
<% //表單回寫(xiě)
  if(request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES) != null) { //如果request中取出的表單回寫(xiě)bean不為空
    out.print(RmVoHelper.writeBackMapToForm((java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES))); //輸出表單回寫(xiě)方法的腳本
  }
 Map mapt = (java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES);
 System.out.print("infois:"+mapt.entrySet());
 out.print("alert(1);");
%>
</script>
 
//上面語(yǔ)句實(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回寫(xiě)表單方法
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;                
            }  
          }
        }
      }
    }  
           
  }
}

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

相關(guān)文章

  • Java中List分片方式詳細(xì)解析

    Java中List分片方式詳細(xì)解析

    這篇文章主要介紹了Java中List分片方式詳細(xì)解析,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-09-09
  • 排查Java進(jìn)程內(nèi)存占比過(guò)高的方法

    排查Java進(jìn)程內(nèi)存占比過(guò)高的方法

    某天下午運(yùn)維反應(yīng)集成環(huán)境的一個(gè)Java服務(wù)內(nèi)存飆高,內(nèi)存耗的太高了,會(huì)疑似內(nèi)存泄漏,所以本文記一次排查Java進(jìn)程內(nèi)存占比過(guò)高的解決方法,需要的朋友可以參考下
    2023-10-10
  • Spring+Quartz配置定時(shí)任務(wù)實(shí)現(xiàn)代碼

    Spring+Quartz配置定時(shí)任務(wù)實(shí)現(xiàn)代碼

    這篇文章主要介紹了Spring+Quartz配置定時(shí)任務(wù)實(shí)現(xiàn)代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-04-04
  • spring boot實(shí)現(xiàn)自動(dòng)輸出word文檔功能的實(shí)例代碼

    spring boot實(shí)現(xiàn)自動(dòng)輸出word文檔功能的實(shí)例代碼

    這篇文章主要介紹了spring boot實(shí)現(xiàn)自動(dòng)輸出word文檔功能的實(shí)例代碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • Mybatis 緩存原理及失效情況解析

    Mybatis 緩存原理及失效情況解析

    這篇文章主要介紹了Mybatis 緩存原理及失效情況解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • SpringBoot整合Shiro的環(huán)境搭建教程

    SpringBoot整合Shiro的環(huán)境搭建教程

    這篇文章主要為大家詳細(xì)介紹了SpringBoot整合Shiro的環(huán)境搭建教程,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以了解一下
    2022-12-12
  • Struts 2 配置Action詳解

    Struts 2 配置Action詳解

    本篇文章主要介紹了Struts 2 配置Action詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-10-10
  • mybatis 通過(guò)攔截器打印完整的sql語(yǔ)句以及執(zhí)行結(jié)果操作

    mybatis 通過(guò)攔截器打印完整的sql語(yǔ)句以及執(zhí)行結(jié)果操作

    這篇文章主要介紹了mybatis 通過(guò)攔截器打印完整的sql語(yǔ)句以及執(zhí)行結(jié)果操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-10-10
  • IDEA2023.1.3安裝教程及下載(圖文)

    IDEA2023.1.3安裝教程及下載(圖文)

    最新變化是在IDEA?2023.1中,對(duì)新UI做出了大量改進(jìn),本文主要介紹了IDEA2023.1.3安裝教程及下載,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-10-10
  • Java中線程的等待與喚醒_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理

    Java中線程的等待與喚醒_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理

    在Object.java中,定義了wait(), notify()和notifyAll()等接口。wait()的作用是讓當(dāng)前線程進(jìn)入等待狀態(tài),同時(shí),wait()也會(huì)讓當(dāng)前線程釋放它所持有的鎖。下面通過(guò)本文給大家介紹Java中線程的等待與喚醒知識(shí),感興趣的朋友一起看看吧
    2017-05-05

最新評(píng)論