Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将使用javascript动态创建的HTML表发送到另一个页面(servlet、jsp等)?_Javascript_Ajax_Dom_Servlets - Fatal编程技术网

如何将使用javascript动态创建的HTML表发送到另一个页面(servlet、jsp等)?

如何将使用javascript动态创建的HTML表发送到另一个页面(servlet、jsp等)?,javascript,ajax,dom,servlets,Javascript,Ajax,Dom,Servlets,如何将使用javascript动态创建的HTML表发送到另一个页面(servlet、jsp等) 我的代码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html" charset="utf-8"> <title>Insert title here</title> <script type="text/javasc

如何将使用javascript动态创建的HTML表发送到另一个页面(servlet、jsp等)

我的代码:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8">
<title>Insert title here</title>
<script type="text/javascript">
function createTable(numberOfRows) {
    for ( var i = 1; i < numberOfRows; i++) {
        var tr = document.createElement("tr");
        var tableData = ['hello','world','hi','bye'];
        for ( var j = 0; j < tableData.length; j++) {
            var td = document.createElement("td");
            var data = document.createTextNode(tableData[j]);
            td.appendChild(data);
            tr.appendChild(td);
        }
        document.getElementById("table1").appendChild(tr);
    }
}
function sendTableToAnotherPage(){
// **what should be the code here,to fetch the table created using above function
//and send it to servlet or jsp page via AJAX.**
}
</script>
</head>
<body>
        <table id="table1">
        </table>
<button type="button" onclick="createTable(5)">Create Table</button>
<input type="button" value="Save" onclick="sendTableToAnotherPage()">
</body>
</html>

在此处插入标题
函数createTable(numberOfRows){
对于(变量i=1;i
我在从servlet/jsp页面获取表数据时遇到了困难。
非常感谢您的帮助。

如果表和数据相同,您可以将table.innerHTML传递到其他页面。
例如:


函数createTable(numberOfRows){
对于(变量i=1;i
您可以将此表页面包含在右侧,而不是发送?使用@includeSend表数据作为JSONinstead@susheel你可以将整个表保存为字符串,并根据需要检索和使用to@EshaJain如何使用参数=innerHtmlValue来解释调用serlvet/url的过程。。。在下一页中再次设置,您能进一步解释吗?Hitesh,对于任何HTML对象,您都可以将InnerHTML作为文本。。。如果您的表是“TABLE1”,则document.getElementById(“TABLE1”).InnerHtmlone您获得此文本后,将其传递到另一个页面以将另一个serlvet append传递到URL并启动。。。
<script type="text/javascript">
function createTable(numberOfRows) {
    for ( var i = 1; i < numberOfRows; i++) {
        var tr = document.createElement("tr");
        var tableData = ['hello','world','hi','bye'];
        for ( var j = 0; j < tableData.length; j++) {
            var td = document.createElement("td");
            var data = document.createTextNode(tableData[j]);
            td.appendChild(data);
            tr.appendChild(td);
        }
        document.getElementById("table1").appendChild(tr);
    }
}
function sendTableToAnotherPage(){
    document.getElementById("table2").innerHTML = document.getElementById("table1").innerHTML;
}
</script>
         <table id="table2" border="2">

        </table>
        <table id="table1">
        </table>
<button type="button" onclick="createTable(5)">Create Table</button>
<input type="button" value="Save" onclick="sendTableToAnotherPage()">