日期:2014-05-16 浏览次数:20333 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <html> <head> <script type="text/javascript" src="plugins/jquery/js/jquery.js"></script> <script type='text/javascript' src='plugins/jquery/js/jquery.autocomplete.js'></script> <link rel="stylesheet" type="text/css" href="plugins/jquery/css/jquery.autocomplete.css" /> <script type="text/javascript"> $(document).ready(function() { $("#labTime").html("time:" + new Date()); setInterval('$("#labTime").html("time:" + new Date());', 1000); //var cities = ["中文","中国","国家","中文国家"]; //$("#content").focus().autocomplete(cities,{matchContains: true,minChars: 1}); initialComplete(null); }); function initialComplete(data){ $("#content").focus().autocomplete("test!getList", { delay:10, minChars:1, matchSubset:0, matchContains:true, cacheLength:10, autoFill:true }); } </script> </head> <body> <center> <div> <h4 id="labTime"></h1> <form action="test!execute" method="post"> <img src="images/psb.jpg" width="500px" height="200px"></img><br> <input type="text" name="content" size="50" id="content" /> <input type="submit" value="Search"> </form> </div> </center> </body> </html>
public String getList() throws Exception { System.out.println("content:(" + content + ") q:(" + q + ")"); //String[] str = {"中文","中国","国家","中文国家"}; String[] str = {"a文","a国","家a","b文国家"}; HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=utf-8"); PrintWriter out; out = response.getWriter(); List list = new ArrayList(); for(int i = 0 ; i < str.length; i ++){ list.add(str[i]); } JSONArray array = JSONArray.fromObject( list ); out.println(array.toString()); out.close(); return null; }