我在一个jsp中有arraylist。我想在另一个jsp上的java脚本中使用arraylist值。你能告诉我怎么做。下面是我的代码。我有两个jsp。
获取用户.jsp
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
String query = "select user_registeration_code from system_user_master where user_first_name ='"+firstname+"' and user_last_name='"+lastname+"' and user_phone_no='"+emp_id+"'";
st = conn.createStatement();
ArrayList<String> addressLists1 = new ArrayList<String>();
ResultSet rs = st.executeQuery(query);
while(rs.next())
{
addressLists1.add(rs.getString("user_registeration_code"));
}
out.println(addressLists1.size());
//out.println(data);
request.setAttribute("top", addressLists1);
第二个.jsp
< script type = "text/javascript" >
function showEmp(emp_value) {
var fname = document.getElementById("txtfirstname").value;
alert(fname);
var lname = document.getElementById("txtlastname").value;
alert(lname);
if (document.getElementById("txtmobileno").value != "") {
alert("1");
xmlHttp = GetXmlHttpObject();
if (xmlHttp == null) {
alert("2");
alert("Browser does not support HTTP Request");
return;
}
var url = "getuser.jsp";
url = url + "?emp_id=" + emp_value + "&firstname=" + fname + "&lastname=" + lname;
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
} else {
alert("Please Select Employee Id");
}
}
function stateChanged() {
alert("3");
document.getElementById("txtfirstname").value = "";
document.getElementById("txtmobileno").value = "";
if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
alert("4");
var showdata = [];
showdata = xmlHttp.responseText;
alert("qqqqqqqqq" + showdata.length);
var i;
for (i = 0; i < showdata.length; i++) {
alert("----------------" + showdata.get(i));
}
}
}
function GetXmlHttpObject() {
var xmlHttp = null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
} catch (e) {
//Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
< /script>