how to access the jsp array variable into javascript? -
i want access jsp array in javascript. how possible?
jspcode
<%! string s[]; %> <% list l=(list)request.getattribute("listresource"); system.out.println("the elements in list::"+l); if(l!=null) { system.out.println("the size of list::"+l.size()); int siz=l.size(); iterator itr=l.iterator(); while(itr.hasnext()) { s=new string[siz]; int i=0; s[i]=itr.next().tostring(); system.out.println("the elments are:"+s[i]); i++; } } %>
javascriptcode
function verify_details() { var resourceid=document.getelementbyid("res").value; var rid=new array(); rid=<%=s%> alert(rid[0]); }
i tried not getting values.
jsp code executed @ server side, , generates text. of text happens javascript code. javascript code executed @ client side, java array doesn't exist anymore data structure.
when write
rid=<%=s%>
you're asking generate following string : "rid=" + s.tostring()
s
being string array, generated javascript code :
rid=[ljava.lang.string;@1242719c
and not valid javascript code.
javascript code, when you're generating jsp, not different html code. if want generate code rid = ['a', 'b', 'c'];
string java array containing "a", "b" , "c", need iterate through java array , output single quote followed current string followed single quote followed comma. additionnally, should escape each string transform quote character \', newline character \n, etc. use stringescapeutils.escapejavascript
commons-lang that.
Comments
Post a Comment