2017-07-08 83 views

回答

0

你可以试试我的代码,根据您的要求:

<table> 
<tr> 
    <td> 
     <select name="choice_type"> 
     <option>select</option> 
     <option value="part_type">part_type</option> 
     <option value="category">category</option> 
     <option value="names">names</option> 
     </select>  
    </td> 
</tr> 
<tr> 
    <th>VAL</th> 
    <th>VAL DESC</th> 
</tr> 
<tr> 
    <td> <input type="text" name="val" id="val" size="15" /></td> 
    <td> <input type="text" name="val_desc" id="val_desc" size="15" /></td> 
</tr> 

的的getData()函数如下:

function getData(){ 
xmlHttp=GetXmlHttpObject() 
var id=document.getElementById("choice_type").value; 
var url="choice_retrieval.jsp";//The code for this file is defined below 
url=url+"?choice_type="+id; 
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true) 
xmlHttp.send(null); 
} 

function stateChanged(){ 
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
var showdata = xmlHttp.responseText; 
var strar = showdata.split(":"); 
if(strar.length>1){ 
var strname = strar[1]; 
document.getElementById("val").value= strar[1]; 
document.getElementById("val_desc").value= strar[2]; 
} 
} 

的代码片段对于choice_retrieval.jsp如下所示WS:

<% 
String ch = request.getParameter("choice_type").toString(); 
System.out.println(ch); 
String data =""; 
try{ 
    Class.forName("com.mysql.jdbc.Driver"); 
    Connection con = DriverManager.getConnection("jdbc:mysql://", "", ""); 
    Statement st=con.createStatement(); 
    ResultSet rs=st.executeQuery("select * from master_panel where 
    choice_type='"+ch+"'"); 
    while(rs.next()) 
    { 
     data = ":" + rs.getString("val") + ": " + rs.getString("val_desc"); 
    } 
    out.println(data); 
    System.out.println(data); 
} 
catch(Exception e) { 
    System.out.println(e); 
} 
%> 

我认为它可以帮助你,万事如意..