这是我的代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/demo"
user="root" password="root"/>
<sql:query dataSource="${snapshot}" var="list">
SELECT * from EmoloyeeSample;
</sql:query>
<form action="some.jsp" method="get">
<select name="id" id="name" onkeyup="doSomething(this.value);">
<option value="0">Select an Employee</option>
<c:forEach var="employee" items="${list.rows}">
<option value="${employee.id}">${employee.name}</option>
</c:forEach>
</select>
<input type="submit" value="Submit" >
<script>
$(function() {
var availableTags=${list}
$( "#name" ).autocomplete({
source: availableTags
});
});
</script>
</form>
</body>
</html>
这里我从$ {list}中的数据库中获取值,所有值都显示在下拉列表中,但我的要求是当用户按下s时,只有名称为initial的名称必须显示在下拉列表中。