一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務(wù)器之家 - 編程語言 - JAVA教程 - form表單回寫技術(shù)java實(shí)現(xiàn)

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

2020-04-20 13:58BeGit JAVA教程

這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)form表單回寫技術(shù)的相關(guān)資料,需要的朋友可以參考下

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

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
   * 回寫表單
   *
   * @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對(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)鍵語句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)容,希望對(duì)大家的學(xué)習(xí)有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 91国内精品 | 成人久久18免费网站 | 小泽玛丽av无码观看 | 福利视频一区二区三区 | 暖暖的视频完整视频韩国免费 | 亚洲四虎永久在线播放 | 公园暴露娇妻小说 | 特黄特级高清免费视频毛片 | 欧美亚洲免费 | 国产精品久久久久久网站 | 亚洲成年网站在线观看 | 男人插曲女人下面 | 大陆男同志gayxxx | 91在线精品视频 | 美女脱了内裤让男桶爽 | 女人用粗大自熨喷水在线视频 | 亚洲 欧美 国产 在线观看 | 亚洲黄视频在线观看 | 精品人人做人人爽久久久 | 男女全黄h全肉细节文 | 小sao货水好多真紧h的视频 | 女子监狱第二季未删减在线看 | 毛片大全免费看 | 亚洲欧美日韩精品 | 国产尤物精品视频 | 帅小伙和警官同性3p | v视界影院.vsjla | 天天做天天爽天天谢 | 国产永久一区二区三区 | 9热在线精品视频观看 | 国产va欧美va在线观看 | 门卫老张和女警花小说 | 青青青久在线视频免费观看 | 欧美综合在线 | 牛人国产偷窥女洗浴在线观看 | 波多野结衣中文字幕 | 日本不卡在线视频高清免费 | 日韩精品一区二区三区免费视频 | 五月激情丁香婷婷综合第九 | 国产一区二区在线看 | 国产精品1页 |