I want to pass JavaScript variable from one JSP page to other.
In my first JSP page, I create a dynamic table based on database queries and I want to send this table to second JSP page, what I have done so far is
<form id="excelForm">
<input type="submit" value="Export to CSV" onclick="myFun();"/>
<input type="hidden" name="pagename" value="Practice/AfterSubmit" />
</form>
<table id="tableContent" border="1">
.... approx 50-3000 rows
</table>
<script>
function myFun(){
console.log("Event sucess");
var tableData = document.getElementById("tableContent").outerHTML;
var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", "tableData");
input.setAttribute("value", tableData);
document.getElementById("excelForm").appendChild(input);
}
</script>
And in second JSP page I do,
String myData = request.getParameter("tableData");
It works fine when the table has upto 50 rows, but when the table size grows, so the size of URL grows and I get 400: Bad Request error
Any ideas what can be the optimal way to do this?