java - Spring MVC passing object to JSP and back -
i've controller class initialize method adding list of string model , view.
@requestmapping(value = "/my-site", method = requestmethod.get) public modelandview dostuff(httpservletrequest request){ modelandview modelandview = new modelandview("do-stuff"); ... list<string> list = arrays.aslist("abc", "cba"); modelandview.addobject("mylist", list); return modelandview; }
question number 1: how access list in jsp file , use later in java script? trying like:
var mylist = []; <c:foreach var="entry" items="'${mylist}'"> mylist.push("${entry}"); </c:foreach>
but reason inside mylist object instead of having 2 elements: "abc" , "cba" have "[abc", " cba]" contains symbols. why? doing wrong , how fix issue?
question number 2: have input button.
<input type="button" id="executebtn" name="executebtn" value="execute">
i want on button click fire event , send mylist
object controller. please provide example method of js side , controller's method.
thanks lot!
why ${mylist}
el expression quoted? rid of single quotes
var mylist = []; <c:foreach var="entry" items="${mylist}"> mylist.push("${entry}"); </c:foreach>
i want on button click fire event , send mylist object controller
the mylist
no longer exists in java form. exists serialized format in mylist
var object. you'll need serialize format web application can understand: form object, comma separated list, json, xml, etc.
Comments
Post a Comment