私は、データベースからデータをロードし、ドロップダウンに挿入しようとしています: データを取得することはできませんよようデータベースからデータを取得し、spring mvcを使用してjspで表示する方法は?
私のjavascriptが見えます:私はデータをロードしようとしています
<script type="text/javascript">
function getEmployee(row)
{
// $('#brand'+row)[0].options.length = 0;
var xmlhttp;
if (window.XMLHttpRequest)
{//code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var status=xmlhttp.responseText;
var x = document.getElementById("employee"+row);
var option = document.createElement("option");
option.text = "";
x.add(option);
var temp = status.split("#");
for(var i=1;i<temp.length;i++)
{
var temp_val=temp[i].split("//");
$('#employee'+row).append(new Option(temp_val[1],temp_val[0]));
}
}
}
xmlhttp.open("GET","LoadEmployee",true);
xmlhttp.send();
}
function loadEmployee()
{
for(var i=1;i<=10;i++)
{
getEmployee(i)
}
}
同じjspの下にドロップダウン:
@RequestMapping(value = "/LoadEmployee", method = RequestMethod.GET) public void LoadEmployee(HttpServletRequest request, HttpServletResponse response) throws SQLException, IllegalStateException, IOException
{
System.out.println("In Load Brands");
String employee=homeDao.getEmployee();
response.setContentType("text/plain");
response.getWriter().write(employee);
}
私の実装を次のように
パブリッククラスHomeimplはHomeDao {
@Override
public String getEmployee() {
String models="";
String query = "SELECT member_name FROM mobike.mst_memberdetail;";
System.out.println(query);
try
{
ResultSet rs = null;
Statement st = null;
Connection con = com.mobike.datasource.DbConnection.getDataSource();
st = con.createStatement();
rs = st.executeQuery(query);
rs.close();
st.close();
con.close();
}
catch (Exception e){System.out.println(e);}
return models;
}