I am dealing with an Object ArrayList that contains various variables, stored in an ArrayList of Objects. I then convert it to a JSONArray and pass it to a JSP page. How can I display these objects in a textarea on the JSP page using JavaScript?
public class myObject{
private String fileName;
private String filePath;
private List<String> messages;
//Constructor, empty constructor and accessor methods.
}
In my Java Controller,
ArrayList<myObject> filesContainer = //obtained from a source file
JSONArray jsFileList = new JSONArray(fileSources);
ModelAndView mnv = new ModelAndView();
mnv.addObject("fileList", jsFileList);
mnv.setViewName("forward:Test.jsp");
return mnv;
In my JSP page, I have created a text area:
<textarea rows="10" cols="50" id="display"></textarea>
<script>
function fileList(){
<% JSONArray fileList;
if(request.getAttribute("fileList") != null){
fileList = (JSONArray) request.getAttribute("fileList");
%>
<% } %>
}
</script>
How would I go about accessing the fileName and filePath in my JSP file?