-3

What's the problem in this Java code,there is a constant red line under the for loop, the code does work in a Java class but not in this one:

<%!
          EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("Dima_TestPU");
        RegionJpaController djc = new RegionJpaController(emf); 
        List<Region> lstRegion = djc.findRegionEntities(); 
        for( Region device : lstRegion ) {
            System.out.println(device.getId());
            System.out.println(device.getName());
            System.out.println(device.getLatitude());
        }
%>
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175

1 Answers1

0

It's because JavaScript has nothing to do with Java. You are messing around with syntax of different languages.

In JavaScript for loop looks like this:

for (var i in myArray) {
    console.log(myArray[i]);
}

or

for (var i = 0; i < myArray.length; i++) {
    console.log(myArray[i]);
}
Justinas
  • 41,402
  • 5
  • 66
  • 96
  • 1
    `for...in` statement could be used, but for iterating arrays `for-in` should be avoided, that statement is meant to enumerate object properties src: [loop-through-an-array-in-javascript](http://stackoverflow.com/questions/3010840/loop-through-an-array-in-javascript#answer-3010848) – Kevin Kloet Oct 21 '16 at 07:04
  • I am using JSP and it says online that you can add Java code in a Java server Page – Abira Abid Oct 25 '16 at 07:57