Reputation: 13395
There is list of Request
objects as session attribute requests
. How to get items from there in javascript code? Request
has fields id,requestId,beds,days,fio
. Session attribute has name requests
.
I set session attribute
session.setAttribute("requests", adminService.getUncheckedRequests());
It's a list of objects List<Request>
.
Request is object
public class Request extends Entity {
private int beds;
private Long classId;
private int days;
private int isChecked;
private String fio;
public int getBeds() {
return beds;
}
public void setBeds(int beds) {
this.beds = beds;
}
public Long getClassId() {
return classId;
}
public void setClassId(Long classId) {
this.classId = classId;
}
public int getDays() {
return days;
}
public void setDays(int days) {
this.days = days;
}
public int getIsChecked() {
return isChecked;
}
public void setIsChecked(int isChecked) {
this.isChecked = isChecked;
}
public String getFio() {
return fio;
}
public void setFio(String fio) {
this.fio = fio;
}
}
How to get items of this attribute in javascript code
function getItems() {
//get list of objects and iterate through it
}
Upvotes: 0
Views: 5663
Reputation: 2202
You can't directly. Session is stored on server, while the JS is executed in the client's browser. To access session variables from javascript you can send a ajax request to the web server and return desired variables to the JS as a response to that request.
Upvotes: 1