如何让JS获取Struts2里面的List数组的数据
publicclassmoveextendsActionSupportimplementsServletRequestAware{privatestaticfinallo...
public class move extends ActionSupport implements ServletRequestAware{
private static final long serialVersionUID = 1L;
private List<UserModel> umList=new ArrayList<UserModel>();
private HttpServletRequest request;
private DAO daos = new DAO();
private List list1=new ArrayList();
private List list2=new ArrayList();
private int num;
private String types;
private String hours;
private String minute;
public String getHours() {
return hours;
}
public void setHours(String hours) {
this.hours = hours;
}
public String getTypes() {
return types;
}
public void setTypes(String types) {
this.types = types;
}
public String getMinute() {
return minute;
}
public void setMinute(String minute) {
this.minute = minute;
}
public List<UserModel> getUmList() {
return umList;
}
public void setUmList(List<UserModel> umList) {
this.umList = umList;
}
public String execute() throws Exception {
String sql = "select * from move where type='" + getTypes()+"' and minute ='"+getMinute()+"' and hour='"+getHours()+"'";
ResultSet rS = daos.executeQuery(sql);
ResultSetMetaData rsmd=rS.getMetaData();
System.out.println(getTypes());
System.out.println(getHours());
System.out.println(getMinute());
try {
while(rS.next()) {
UserModel um=new UserModel();
int i=0;
um.setTypes(rS.getString(i+2));
um.setHours(rS.getString(i+3));
um.setMinute(rS.getString(i+4));
um.setUserid(rS.getString(i+5));
um.setName(rS.getString(i+6));
um.setXstate(rS.getString(i+7));
um.setYstate(rS.getString(i+8));
umList.add(um);
System.out.println(umList);
request.setAttribute("users", umList);
}
list1.add(umList.get(0).getXstate());
list2.add(umList.get(0).getYstate());
int size=list1.size() ;
request.setAttribute("size", size);
request.setAttribute("list1", list1);
request.setAttribute("list2", list2);
return "success";
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "error";
}
}
@Override
public void setServletRequest(HttpServletRequest request)
{
this.request = request;
}
}
JSP页面:
function initMap()
{
createMap();//创建地图
setMapEvent();//设置地图事件
addMapControl();//向地图添加控件
var size="<s:property value="#request.size"/>";
for (var i = 0; i <size; i++) {
var sw ="<s:property value="#request[list1[i]]"/>";
alert(sw);
var ne ="<s:property value="#request[list2[i]]"/>";
var point = new BMap.Point(sw,ne );
addMarker(point);
}
function addMarker(point){
var marker = new BMap.Marker(point);
map.addOverlay(marker);
}
我的前端JS想获取数组里Xstate和Ystate两个数据,但我怎么写都访问不出来,我是新手,求帮忙,我不清楚怎么调用这两个数据的JS上。 展开
private static final long serialVersionUID = 1L;
private List<UserModel> umList=new ArrayList<UserModel>();
private HttpServletRequest request;
private DAO daos = new DAO();
private List list1=new ArrayList();
private List list2=new ArrayList();
private int num;
private String types;
private String hours;
private String minute;
public String getHours() {
return hours;
}
public void setHours(String hours) {
this.hours = hours;
}
public String getTypes() {
return types;
}
public void setTypes(String types) {
this.types = types;
}
public String getMinute() {
return minute;
}
public void setMinute(String minute) {
this.minute = minute;
}
public List<UserModel> getUmList() {
return umList;
}
public void setUmList(List<UserModel> umList) {
this.umList = umList;
}
public String execute() throws Exception {
String sql = "select * from move where type='" + getTypes()+"' and minute ='"+getMinute()+"' and hour='"+getHours()+"'";
ResultSet rS = daos.executeQuery(sql);
ResultSetMetaData rsmd=rS.getMetaData();
System.out.println(getTypes());
System.out.println(getHours());
System.out.println(getMinute());
try {
while(rS.next()) {
UserModel um=new UserModel();
int i=0;
um.setTypes(rS.getString(i+2));
um.setHours(rS.getString(i+3));
um.setMinute(rS.getString(i+4));
um.setUserid(rS.getString(i+5));
um.setName(rS.getString(i+6));
um.setXstate(rS.getString(i+7));
um.setYstate(rS.getString(i+8));
umList.add(um);
System.out.println(umList);
request.setAttribute("users", umList);
}
list1.add(umList.get(0).getXstate());
list2.add(umList.get(0).getYstate());
int size=list1.size() ;
request.setAttribute("size", size);
request.setAttribute("list1", list1);
request.setAttribute("list2", list2);
return "success";
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "error";
}
}
@Override
public void setServletRequest(HttpServletRequest request)
{
this.request = request;
}
}
JSP页面:
function initMap()
{
createMap();//创建地图
setMapEvent();//设置地图事件
addMapControl();//向地图添加控件
var size="<s:property value="#request.size"/>";
for (var i = 0; i <size; i++) {
var sw ="<s:property value="#request[list1[i]]"/>";
alert(sw);
var ne ="<s:property value="#request[list2[i]]"/>";
var point = new BMap.Point(sw,ne );
addMarker(point);
}
function addMarker(point){
var marker = new BMap.Marker(point);
map.addOverlay(marker);
}
我的前端JS想获取数组里Xstate和Ystate两个数据,但我怎么写都访问不出来,我是新手,求帮忙,我不清楚怎么调用这两个数据的JS上。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询