日期:2014-05-18  浏览次数:20717 次

JSP登录问题求救 急 急 在线等
我现在做了一个登录的界面,界面有一个输入ID和密码的文本框,还有一个下来菜单。
当我输入一个ID的时候,管理员给用户ID分配的功能(角色)能够在下拉菜单中显示出来。改如何实现呢。下面是我写的一个下拉菜单,但是SQL语句中的条件“C_Usr_Id”不知道改如何得到,谢谢大家
<select   size= "1 "   name= "C_Roles_Name "   style= "width:133 ">
  <%  
ConnDB2Imp   conndb   =   new   ConnDB2Imp();//连接DB
String   sql   =   "select   a.C_Usr_ID,b.C_Role_ID,c.C_Roles_Name   from   sys_usr   a,sys_role_usr   b,sys_roles   c   where   a.C_Usr_ID=b.C_Usr_ID   and   c.C_Roles_ID=b.C_Role_ID   and   a.C_Usr_ID= ' "+   C_Usr_Id   + " ' ";                    
ResultSet   rs   =   conndb.returnSelectRs(sql);            
try{      
        while(rs.next())      
{
      String   Role_Name=rs.getString( "C_Roles_Name ");          
      String     Role_ID=rs.getString( "C_Role_ID ");  
    String     Usr_ID   =   rs.getString( "C_Usr_ID ");    
out.println( " <option   value= ' "   +   Usr_ID   +   " '> "   +   Role_Name   +   " </option> ");  
}    
}catch(Exception   e){e.printStackTrace();}
finally{conndb.closeRs();conndb.closeStmt();conndb.closeConn();}     %>      
  </select>

------解决方案--------------------
页面代码:
<form name= "frm1 ">
<table>
<tr> <td>
<input type= "text " id= "ID " name= "ID " onchange= "return check() "/>
</td> </tr>
<tr> <td>
<select name= "role ">
<option value= "-1 "> select role </option>
</select>
</td> </tr>
</table>
</form>
<script>
var xmlHttp1;
try {
xmlHttp1 = new ActiveXObject( "Msxml2.xmlHttp ");
} catch (e) {
try {
xmlHttp1 = new ActiveXObject( "Microsoft.xmlHttp ");
} catch (e2) {
xmlHttp1 = false;
}
}
function check() {
var ID = document.getElementById( "ID ").value;
if ((ID == null) || (ID.match(/^\s*$/)))return;
// Build the URL to connect to
var url = "/test/checkValue?ID= " + escape(ID);
// Open a connection to the server

xmlHttp1.open( "post ",url, true);
// Setup a function for the server to run when it 's done
xmlHttp1.onreadystatechange = updatePage1;
// Send the request
xmlHttp1.send(null);
}
function updatePage1() {
if (xmlHttp1.readyState == 4 && xmlHttp1.status==200) {
var xmldom = xmlHttp1.responseXML;
var rootElement = xmldom.documentElement;
var roles = rootElement.childNodes;
var select_role = document.frm1.role;
select_role.options[0] = new Option( 'select role ', '-1 ');
for(var i=0;i <roles.length;i++){
select_role.options[i+1]=new Option(roles[i].text,roles[i].text);
}
}
}
</script>

servlet代码:
protected void do