protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8");String keyWord=request.getParameter("keyWord");ajax ajax=new ajax();ajax.setContent(keyWord);List<ajax> list=as.getAjax(ajax);List<String> strings=new ArrayList<String>();for (ajax str : list) {strings.add(str.getContent());}System.out.println(JSONArray.fromObject(strings).toString());response.getWriter().write(JSONArray.fromObject(strings).toString());}
/** * 全局变量 */var xmlHttp;/** * 得到input输入框的内容 */function getMoreContents() { var content=document.getElementById('input'); if(content.value==""){ return; } // alert(content.value); xmlHttp=createXMLHttp(); // alert(xmlHttp); var url="search?keyWord="+escape(content.value); xmlHttp.open("GET",url,true); xmlHttp.onreadystatechange=callback; xmlHttp.send(null);}//获得xmlHttp对象function createXMLHttp () { var xmlHttp; if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); } if(window.ActiveXObject){ xmlHttp=new ActiveXObject("Microsoft.XMLHttp"); if(!xmlHttp){ xmlHttp=new ActiveXObject("Msxml2.XMLHttp"); } } return xmlHttp;}//回调函数function callback () { if(xmlHttp.readyState==4){ if(xmlHttp.status==200){ var result=xmlHttp.responseText; alert(result); var json=eval("("+result+")"); alert(json); } }}//设置关联数据的显示function setContent(contents){ var size=contents.length; for (var i = 0; i < size; i++) { var nextNode=contents[i]; var tr=document.createElement("tr"); var td=document.createElement("td"); td.setAttribute("bgcolor","aliceblue"); td.onmouseover=function() { this.className='mouseOver'; } td.onmouseout=function(){ this.className='mouseOut'; } td.onclick=function(){ } var text=document.createTextNode(nextNode); td.appendChild(text); tr.appendChild(td); document.getElementById('contentTableBody').appendChild(tr); }}