I am trying to create a variable through javascript and use that variable in my spring mvc controller. Unfortunately I can't seem to figure it out and the variable keeps coming up empty.
Here is my javascript where I set the variable:
<script language="JavaScript">
function checkBoxValues() {
checkboxes = document.getElementsByName('message');
var hopeThisWorks = "";
for (var i = 0, n = checkboxes.length; i < n; i++) {
if (checkboxes[i].checked == true) {
message = checkboxes[i].value;
var element = message.split(",");
resubmitMessage(element[0], "" + element[1] + "",element[2]);
var hopeThisWorks = "" + element[2] +"";
alert(hopeThisWorks);
}
}
}
</script>
Then I take this variable and add it to my jsp as a input as follow:
<input name="abc" type="hidden" value="${hopeThisWorks}">
Here is my code in my spring mvc controller:
@RequestMapping(method = RequestMethod.POST, value = "resubmit")
public String resubmit(@RequestParam(value = "abc") String param, Model model) {
model.addAttribute("messageList", param);
return RESUBMIT;
}
Then I call the variable in a jsp file to display the message as follows:
<table class="results table table-striped table-bordered table-condensed">
<thead>
<tr>
<td colspan="10">
<h5>Bulk Resubmit Query Results</h5>
</td>
</tr>
<tr>
<jsp:include page="../commons/a.jsp"/>
<jsp:include page="../commons/b.jsp"/>
<jsp:include page="../commons/c.jsp"/>
<jsp:include page="../commons/d.jsp"/>
<jsp:include page="../commons/e.jsp"/>
<jsp:include page="../commons/f.jsp"/>
<jsp:include page="../commons/g.jsp"/>
<jsp:include page="../commons/h.jsp"/>
</tr>
<p>Test <c:out value="${messageList}"/></p>
input type=hiddenelement in your HTML form. or use Ajax to POST