ArrayList를 수신하여 배열에 배치하는 JSP 페이지에 ArrayList를 전달하는 서블릿이 있지만이를 저장할 경우 Loc 내의 매개 변수에 액세스 할 수 없습니다.서블릿에 의해 전달 된 복잡한 객체를 자바 스크립트의 배열에 저장
var locations = new Array();
<c:forEach items="${photosName}" var="photo" varStatus="loop">
locations["${loop.index}"] = "${photo}";
</c:forEach>
변수 사진에는 위치 배열에 저장하려는 위도, 경도 및 정확도와 같은 속성이 포함되어 있습니다. 하지만 내가 이런 식으로 저장하면 코드의 다른 부분에서 어떻게 액세스 할 수 있습니까? 내가 뭘 원하는지의
예 :
locations[i].latitude
locations[i].longitude
locations[i].accuracy
어떤 도움을 환영합니다 :) 지금이 시도
:
var locations = new Array();
<c:forEach items="${photosName}" var="photo" varStatus="loop">
locations["${loop.index}"] = JSON.stringify("${photo}");
</c:forEach>
alert("latitude: "+locations[0].latitude+ " longitude: "+locations[0].longitude);
그것은 인쇄 위도 : 정의되지 않은 경도 : 정의되지 않은. json.stringify가 작동하도록 뭔가를 가져와야합니까? JSP에서
사진 개체는이 클래스에 의해 표현된다 :
@Entity
public class Loc implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private long id;
private double latitude;
private double longitude;
private long time;
private double accuracy;
private int processed;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public double getLatitude() {
return this.latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return this.longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public long getTime() {
return this.time;
}
public void setTime(long time) {
this.time = time;
}
@Override
public String toString() {
return "latitude: " + latitude + " longitude: " + longitude + "time: "
+ time;
}
public double getAccuracy() {
return accuracy;
}
public void setAccuracy(double accuracy) {
this.accuracy = accuracy;
}
public int getProcessed() {
return processed;
}
public void setProcessed(int processed) {
this.processed = processed;
}
}
를? – vlio20
'photList'를 호출 한 자바 객체의 목록이 있다고 가정 해 보겠습니다. 지금 당신이해야 할 일은 자바 스크립트를 변환하는 것입니다. 이것을 시도하십시오 :'var photo list = JSON.stringify (<% gson.toJson (photoList) .toString %>)' – vlio20
for 루프 전에? – JoaoFilipeClementeMartins