資源描述:
《16-實現(xiàn)仿GoogleSuggest自動補全的功能》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在教育資源-天天文庫。
1、AutoComplete.java:importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.ServletException;importjava.io.IOException;/***CreatedbyIntelliJIDEA.*User:ming*Date:2
2、008-6-14*Time:14:17:00*TochangethistemplateuseFile
3、Settings
4、FileTemplates.*接收用戶端請求*/publicclassAutoCompleteextendsHttpServlet{???protectedvoiddoGet(HttpServletRequesthttpServletRequest,HttpServletResponsehttpServletResponse)throwsServletException,IOE
5、xception{???????//表示頁面?zhèn)鬟^來的字符串,用于和服務器段的單詞進行完整匹配???????Stringword=httpServletRequest.getParameter("word");???????//將字符串保存在request對象中???????httpServletRequest.setAttribute("word",word);???????//將請求轉(zhuǎn)發(fā)給視圖層(注意AJAX中,這個所謂的視圖層不返回頁面,只返回數(shù)據(jù),所以也可以稱作使一個數(shù)據(jù)層)???????
6、httpServletRequest.getRequestDispatcher("wordxml.jsp").???????????????forward(httpServletRequest,httpServletResponse);???}???protectedvoiddoPost(HttpServletRequesthttpServletRequest,HttpServletResponsehttpServletResponse)throwsServletException,IOExce
7、ption{???????doGet(httpServletRequest,httpServletResponse);???//TochangebodyofoverriddenmethodsuseFile
8、Settings
9、FileTemplates.???}}wordxml.jsp:<%--itcast.cn的ajax自動補全實例--%><%@pagecontentType="
10、text/xml;charset=UTF-8"language="java"%><%???//過濾???//頁面端傳送的字符串???Stringword=(String)request.getAttribute("word");%>???<%if("absolute".startsWith(word){%>???absolute
11、???<%}%>???<%if("anyone".startsWith(word){%>???anyone???<%}%>???<%if("anything".startsWith(word){%>???anything???<%}%>???<%if("apple".startsWith(word){%>???apple???<%}%>???<%if("abandon".startsWith(word){%>???12、ord>abandon???<%}%>???<%if("breach".startsWith(word){%>???breach???<%}%>???<%if("break".startsWith(word){%>???break???<%}%>???<%if("boolean".startsWith(word){%>???boolean???<%}%>JQueryAutoComplete