V
V
Viktoria Smirnova2018-03-03 10:18:01
MySQL
Viktoria Smirnova, 2018-03-03 10:18:01

Goggle map?

Specialists and semi-specialists, I ask for help: in the JSP file I have a script that allows you to place marks on the Google map:

var stationList = [


       {"latlng":[43.00000000, 43.00000000], name:"Shinagawa Station", url:"/MastersServlet?action=listUser", address:"-----str"},
        {"latlng":[43.00000000, 43.00000000], name:"Station", url:"../barber/beuaty/masterslist.jsp", address:"-----str" },

        {"latlng":[43.00000000, 43.00000000], name:"Tokyo1 Station", url:"second.php", address:"----str"},
        {"latlng":[43.00000000, 43.00000000], name:"Shinagawa1 Station", url:"second.php", address:"-----str"},
        {"latlng":[43.00000000, 43.00000000], name:"Station", url:"second.php", address:"------str" },

        {"latlng":[43.00000000, 43.00000000], name:"Tokyo2 Station", url:"second.php", address:"----- str"},
        {"latlng":[43.00000000, 43.00000000], name:"Shinagawa2 Station", url:"second.php", address:"-----str"},
    ];


I’ll post the whole script if necessary, now the question is: in order not to manually score this whole thing, I think to write it down from the database, which I did, but in the future I can’t pull them out using the JSTL code, or rather, he does not see the data from the database. The database is connected, getters and seters are written, the DAO business is also written, everything is ok with the controller.

<code lang="javascript">
   <c:forEach items="${users}" var="user">
    var stationList = [
       {"latlng":[<c:out value="${user.lat}" />, <c:out value="${user.lng}" />], name:"<c:out value="${user.name}" />", url:"<c:out value="${user.url}" />", address:"<c:out value="${user.addres}" />"},
      </с:forEach>
</code>


DAO

public List<User> getAllUsers() {
        List<User> users = new ArrayList<User>();
        try {
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery("select * from table");
            while (rs.next()) {
                User user = new User();
                user.setName(rs.getString("name"));
                user.setAddres(rs.getString("addres"));
                user.setLat(rs.getString("lat"));
                user.setLng(rs.getString("lng"));
                /* user.setMasteregistration(rs.getDate("masterregistration"));*/
                users.add(user);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return users;
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yerlan Ibraev, 2018-03-03
@Vika7

The loop must be done inside the formed array.
And where is the closing tag of the cycle?
And why multiple lines?
In the loop body, form a string with coordinates.
Those. you need to write it once, it will just be repeated / displayed several times.

A
Alexey Kopendakov, 2018-03-03
@alex_kag

Isn't it easier to pass a ready-made array to jsp?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question