JSP scriptlets in javascript

Hi,
can I have JSP scriplets in a javascript code ?
Thank you.
LVL 9
matthew016Asked:
Who is Participating?
 
koppchaCommented:
This is an example

<script>

  var arry = new Array();
 //This is a scriptlet
  <%
  String[] strArray = new String[] {"A", "B", "C"};

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

//This is how the expression are used
  arry[<%=i%>] = "<%=strArray[i]%>";
  <% } %>
  alert(arry.length);

</script>


Relate this to what you are doing and let me know the specific questions that you have
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
MeritorCommented:
It depands on the situation.
Will you describe what excetly you want to do?
0
 
koppchaCommented:
Usually we end up using expressions in the javascript. But again you need to let us know the situation ,what you are trying to achieve.
0
 
matthew016Author Commented:
I wanted to affect a jsp variable to a javascript variable.
It is better to avoid this ?
0
 
koppchaCommented:
You can use expressions. you want to assign a Java script variable to a JSP value right ?
0
 
matthew016Author Commented:
expressions ?
well js to jsp and jsp to js, i wondered how I could do this.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.