Hi,
this is a bit more tricky since the JavaScript and the JSP code doesn't really execute in the same environment. There is not a direct communication between them both but take a look at this (really simple) example of how you could pass a Java variable to the JavaScript environment:
// MY JSP FILE <% //.. previous stuff javax.jcr.NodeIterator iter =toNode.getNodes(); long count =iter.getSize(); //..... more stuff %> <script type="text/javascript"> var myCountValue = "<%=count%>"; </script>
Another way of actually doing this would be to make an ajax call from a JavaScript function to the servlet. Then make sure that the servlet will return a JSON answer that the JavaScript function can parse and then use.
Hope that will point you in some direction.
/Johan