var tab = document.getElementById("tab") tab.innerHTML=""; tab.innerHTML+="<tr><td>xx:</td><td><input id='' name='' type='text' value=''/></td></tr>";
前台页面js 事件
function savexxbtn(){ var sx=$('#t_ylxx').datagrid("getSelected"); $('#xxform').form('submit', { url:'gxservlet?methodName=updatemapxx&id='+sx.id+'&tabname='+sx.tableName, contentType: "application/x-www-form-urlencoded; charset=utf-8", dataType:'text', type: 'post', success:function(result){ if(result == 'true'){ alert("更新成功!"); $('#t_exgl').datagrid('load'); } else{ alert(" 更新失败,请重新保存"); } } }); $('#xxdiv').dialog('close'); }
后台servlet
private void updatemapxx(HttpServletRequest request, HttpServletResponse response) { response.setContentType("text/html;charset=utf-8"); Enumeration rnames=request.getParameterNames();//获取通过form提交的name和value Map xxmap=new HashMap(); StringBuffer sb=new StringBuffer(); String id=""; String tabname=""; for (Enumeration e = rnames ; e.hasMoreElements() ;) { String thisName=e.nextElement().toString(); String thisValue=request.getParameter(thisName); System.out.println(thisName+"-------"+thisValue); //得到 数据表名 if("tabname"==thisName || "tabname".equals(thisName)){ tabname=thisValue; } //得到 id if("id"==thisName || "id".equals(thisName)){ id=thisValue; } //去除 id 表明 以及 url 传来的 参数 得到要 表单的 name 和值 (name 为动态可变) if(!"methodName".equals(thisName)&& !"id".equals(thisName) && !"tabname".equals(thisName)){ String ss=thisName+"="+"'"+thisValue+"',"; sb.append(ss); } } String updatess=sb.toString(); //去除 数据库 更新语句的最后一个 ,号 updatess=updatess.substring(0,updatess.length()-1); System.out.println(updatess); System.out.println(id); System.out.println(tabname); try{ GxDao gd= new GxDao(); Boolean res=gd.updatemapxx(tabname,id,updatess); if(res){ response.getWriter().write("true"); } else{response.getWriter().write("false");} response.getWriter().close(); }catch(Exception e){ e.printStackTrace(); } }