2017-01-10 2 views
0

Object ArrayListにはいくつかの変数があり、ObjectのArrayListに格納しています。私はそれをJSONArrayに変換してJSPページに渡します。javascriptでArrayListにアクセスする方法<Object>をJSONArrayに変換しました

<textarea rows="10" cols="50" id="display"></textarea> 

<script> 
    function fileList(){ 
     <% JSONArray fileList; 
     if(request.getAttribute("fileList") != null){ 
      fileList = (JSONArray) request.getAttribute("fileList"); 

      %> 


     <% } %> 
    } 
</script> 
:私はここで私はテキストエリアを作成する必要があり、私のJSPページ内の私のJavaのコントローラー、

ArrayList<myObject> filesContainer = //from source file 
JSONArray jsFileList = new JSONArray(fileSources); 

ModelAndView mnv = new ModelAndView(); 
mnv.addObject("fileList", jsFileList); 
mnv.setViewName("forward:Test.jsp"); 
return mnv; 

でJavaScript

public class myObject{ 
    private String fileName; 
    private String filePath; 
    private List<String> messsage; 

    //Constructor, null constructor and access modifier methods. 

} 

を使用してJSPページ上のテキストエリアでこれらのオブジェクトをどのように表示されません

jspファイルのfileName、filePathにアクセスするにはどうすればよいですか?

答えて

0

は、私がデータを取得する方法..です共有にありがとう...

VARのx = "< %= j.getString( "fileName")%> ";

function fileList(){ 
     <% JSONArray fileList; 
     if(request.getAttribute("fileList") != null){ 
      fileList = (JSONArray) request.getAttribute("fileList");%> 

      <% 
       for(int i=0;i<fileList.length();i++){ %> 

       <% JSONObject j = fileList.getJSONObject(i); %> 
       var x = "<%= j.getString("fileName") %>"; 
       document.getElementById("fileSelector").value += x + "\n"; 

      <% } %> 


     <% } %> 
    }