特效模糊查詢(自動補全)

jsp.......................................
注意添加js包
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'help.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
  <script type="text/javascript" src="<%=basePath %>js/jquery-1.3.2.min.js"></script>
 
       <link rel="stylesheet" type="text/css" href="<%=basePath %>js/jquery.suggest.css">
     <script type="text/javascript" src="<%=basePath %>js/j.dimensions.js"></script>
     <script type="text/javascript" src="<%=basePath %>js/aircity.js"></script>
      <script type="text/javascript" src="<%=basePath %>js/j.suggest.js"></script>
      <script type="text/javascript">
 
  $(function() {
   $
   .ajax({
    type : "post",
    url: "sys/song/findAllSinger.action",
    timeout : 20000,
    error : function() {
     alert('錯誤');
    },
    async : false,
    dataType : "json",
    success : function(data) {
     
   
   $("#arrcity").suggest(data, {
    hot_list : data,
    dataContainer : '#arrcity_3word',
    
    attachObject : '#suggest'
   });
    }});
  });
 </script>
  </head>
 
  <body >
                                <div id="box">
        <h1>仿機票預定智能輸入提示DEMO</h1>
        <input type="hidden" name="arrcity_3word" id="arrcity_3word" value="" />
        <label for="arrcity">出發城市:</label><input type="text" name="arrcity"
         id="arrcity" />
        <div id='suggest' class="ac_results"></div>
 
</div>
  </body>
</html>
從action傳出來的值一定要符合json規範
findAllSinger.action...................................
public void findAllSinger(){
  try {
   Map session = ActionContext.getContext().getSession();
   logger.info("坐席"+session.get(SystemParams.OPERATORID)+"進行了歌手(word:"+word+")模糊查詢!");
    words=singerService.findAllSinger();
    
    String tmp = "{";    
    for (int i = 0; i < words.size(); i++) {
     Gson array = new Gson();
     String str = array.toJson(new String[]{"",words.get(i),"",""});
     //tmp+=i+":"+str+",";
     tmp+='"'+""+i+'"'+":"+str+",";
     //tmp+="sName"+i+":"+str+",";
    }
    tmp=tmp.substring(0, tmp.length()-1);
    
    tmp+="}";
    
    logger.info("str = {} ",tmp);
    outPut(tmp);
  } catch (Exception e) {
   e.printStackTrace();
  }
  
 }
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章