Traverse array list in Javascript file
In my Struts 2 based application, I have an ArrayList. How can I send this ArrayList to a Javascript file so that I can compare list item with element of jsp and show some message based on validation? 开发者_StackOverflow社区How can I use the array list data in Javascript file. I do not want use JSON.
JSON comes to mind - not sure of this example so here is one more
you can use <logic:iterate>
and iterate through your List
, here is example
Your question makes it seem like you want to send the ArrayList to the client directly, this means it will not be processed by a JSP. The easiest way to do this is with JSON, then XML, then perhaps some custom built format which you'd need to parse with JS.
But since you then say that you want to compare a value from the action class to a value in the JSP this means you'll want the comparison done when composing the view on the server and not on the client. For this see the struts2 tag documentation the <s:iterate>
and <s:if>
tags will let you do this.
As your question stands the two ideas are irreconcilable without some guess work.
精彩评论