0
這裏是我的代碼:如何使用Ajax和jQuery在JSP
<%@ 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然後只有名稱具有初始值,因爲s必須顯示在下拉列表中。