Привет, используйте Ajax для извлечения значений из базы данных, используя поле выбора, это может помочь вам
1.mainpage.jsp
<%@page import="java.sql.*"%>
<html>
<head>
<script language="javascript" type="text/javascript">
//AJAX code for retrieving dates from database
var xmlHttp;
var xmlHttp;
function showEmp(str){
if (typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp==null){
alert("Browser does not support XMLHTTP Request");
return;
}
var url="selEmp.jsp";
url +="?count=" +str;
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChange()
{
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("batchdate").innerHTML=xmlHttp.responseText
}
}
</script>
</head>
<body>
<select name='batch' onchange="showEmp(this.value)">
<option value="none">Select</option>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://192.168.40.120:3306/cjet","root","root");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from cjet.batch");
while(rs.next()){
%>
<option value="<%=rs.getString("bname")%>"><%=rs.getString("bname")%></option>
<%
}
%>
</select>
<br>
<div id='batchdate'>
<select name='batchdate' onchange="showCustomer(this.value)">
<option value='-1'></option>
</select>
</div>
</body>
</html>
2.retrieve.jsp
<%@page import="java.sql.*"%>
<%
String no=request.getParameter("count");
String buffer="<select name='batchdate' onchange='showCustomer(this.value)'><option value='-1'>Select</option>";
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://192.168.40.144:3306/cjet","root","root");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from cjet.batchdate where bname='"+no+"' ");
while(rs.next()){
buffer=buffer+"<option value='"+rs.getString(1)+"'>"+rs.getString("courseID")+" </option>";
}
buffer=buffer+"</select>";
response.getWriter().println(buffer);
}
catch(Exception e)
{
System.out.println(e);
}
%>