[英]Get the width of a div that was created in javascript using createElement
[英]Save dynamic data created using createElement(Javascript) to database
我是這個論壇和網頁設計的新手。 我正在嘗試使用JSP設計一個配置文件管理工具,在該工具中動態地添加了(通過javascript createElement)分配了名稱的輸入字段。 我只能將一個記錄保存到數據庫,而其他記錄則被忽略。 我的問題是如何保存動態添加的所有數據? 請幫我。
Javascript代碼:使用以下功能,我可以獲取Javascript數組
function addedu()
{
$(document).ready(function(){
$(".ed").each(function(input){
var value = $(this).val();
var id = $(this).attr('id');
t= id+' : '+ value;
arr.push(t);
});
});
var newinput1 = document.createElement("input");
newinput1.name="i1"
newinput1.className="ed"
newinput1.id="Education"
newinput1.innerHTML = "";
document.getElementById('edu').appendChild(newinput1);
}
JSP代碼:
String edu1=request.getParameter("i1");
Statement st1=con.createStatement();
String sql1="insert into education values('"+pno+"','"+edu1+"');
st1.executeUpdate(sql1);
在客戶端,您可以使用jQuery動態添加行並讀取必要的值。 要訪問表的行,可以使用jQuery選擇器。 然后將數據保存在JavaScript數組中,將其轉換為JSON並將其發送到服務器端。
這是一個示例(使用PHP,但是在這種情況下沒關系):
在服務器端,您需要通過純JDBC進行大量插入,使用BATCH插入,而不是為每個插入語句訪問數據庫一次。
這是一個例子:
如果您決定使用Spring,請參考以下示例:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.