0

Assume I have following code in a jsp file in JavaWeb:

<%
String myList = new String[10];
for(int i=0;i<10;i++){
    myList[i] = String.valueOf(i);
}
%>

Now I want to get the value of the elements of myList in a loop of javascript: Are the following ways are correct?

<script type="text/javascript">
var arr = new Array(10);
for(var i=0;i<10;i++){
    arr[i] = "<%=myList[i]%>"
}
<script>

If not, how could I reach my purpose?

3
  • 1
    Well, if it works then it's probably correct. Otherwise no. Does it work? Commented Oct 24, 2016 at 15:08
  • I haven't test it yet. But commonly it is not right because the value i is the value of javascript and it can not be used in java code in <% %> Commented Oct 24, 2016 at 15:15
  • Possible duplicate of Passing array from .jsp to javascript function Commented Oct 28, 2016 at 6:56

1 Answer 1

0

EDIT : Look at there Passing array from .jsp to javascript function

No, this isn't correct. Because the jsp i will never change.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.