0

Hey guys this must be a silly question for some of you, but I can't go through this problem. I'm trying to pass values from my java object to a javascript array. For some reason it doesn't work. The CanchasPrecios2 Arrays get filled out with undefined values, and won't let me work. The CanchasDescription do get the right values. I've tripled check to see what are the values for the object's price and they are the right ones. Both Price and Descriptions are Strings in their Java Object. Any idea on how to solve it?

THANKS!

   var y = <%=param%>;
   var CanchasDescription = new Array();
   var CanchasPrecios2 = new Array();

   <% for(int i =0; i<owner.getMisCanchas().size(); i++)
    { %>

    CanchasDescription[<%=i%>] = <%= owner.getMisCanchas().get(i).getDescription()%>;
    CanchasPrecios2[<%=i%>] = <%=owner.getMisCanchas().get(i).getPrice()%>; 

   <%}%>
  • You probably need quotes around the string values you are trying to assign. You should also avoid scriptlets in JSPs. – GriffeyDog Oct 29 '13 at 19:21
  • Read the generated source. – SLaks Oct 29 '13 at 19:23
  • You have an XSS hole. – SLaks Oct 29 '13 at 19:24
2

I do now know JSP very well, but aren't you missing the quotes around your printed values from Java? I suppose your code should be something like this:

CanchasDescription[<%=i%>] = "<%= owner.getMisCanchas().get(i).getDescription()%>";
CanchasPrecios2[<%=i%>] = "<%=owner.getMisCanchas().get(i).getPrice()%>";

Take a look at the source code on your browser and see how the javascript code was generated.

0

I got it solved guys, apparently I had a silly mistake after this code that made it undefined. Sorry about that guys. Also just wanted to remind you that there is no need of the quotes, it won't affect in anything as long it is a String. Thanks You very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.