JQuery果然插件很多,找了一个自动完成的插件http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
然后写一个简单的servlet,就搞定了,很不错
$("#someid").autocomplete("../autocomplete");
../autocomplete就是那个servlet,它实现这个方法就够了
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String q=request.getParameter("q");
if(q==null||q.trim().equals("")){
return;
}
List<String> list=new ArrayList<String>();
list.add("google");
list.add("sougou");
list.add("gougle");
list.add("bingo");
for (String str : list) {
if (str.indexOf(q) != -1) {
out.print(str + "/n");
}
}
out.close();
}