<script type="text/javascript">
var request = false;
//根据输入 的登录号获取到该登陆角色列表
function showRoles(){
if(document.getElementById("username").value==""){
return;
}
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
}
if (!request)
alert("Error initializing XMLHttpRequest!");
var username = document.getElementById("username").value;
var url = "/。。。。/loginRoles?sid=" + username;
request.open("GET",url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
function updatePage() {
if (request.readyState == 4 && request.status == 200) {
var response = request.responseText;
var roleArray = response.split("|");
if(roleArray.length <= 1){
alert("输入的登录号有误或者没有角色权限");
return;
}
var count = roleArray.length;
var logonId = document.getElementById("roleSelectOption");
logonId.length = 0;
for(var i = 0 ;i<count-1; i++){
logonId.options.add(new Option(roleArray[i+1],roleArray[i]));
i++;
}
}
}
</script>
Servlet部分
try {
res.setContentType("text/html");
res.setCharacterEncoding("utf-8");
res.getWriter().write(result);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}