J2EE 0.7.2—用ajax实现像google那样的suggest-search功能(简化版)
首先是需要建一个库。考虑可以这样。建立一个拼音的字段对应汉字的,用户打简拼即可查出汉字
sql 代码
- create?table?`j2ee`.`suggest`( ??
- ????`SUGGEST_ID`?int?not?null?auto_increment, ??
- ???`TITLE`?varchar(255), ??
- ????primary?key?(`SUGGEST_ID`) ??
- );??
当然这里为了方便没有这样做。直接查title这个字段了。
其次是action了
java 代码
- package?org.perfect.struts.action; ??
- ??
- import?java.util.List; ??
- import?java.util.Map; ??
- ??
- import?javax.servlet.http.HttpServletRequest; ??
- import?javax.servlet.http.HttpServletResponse; ??
- ??
- import?org.apache.struts.action.ActionForm; ??
- import?org.apache.struts.action.ActionForward; ??
- import?org.apache.struts.action.ActionMapping; ??
- import?org.perfect.struts.dao.SearchSuggestDao; ??
- import?org.perfect.struts.form.LoginForm; ??
- import?org.perfect.struts.form.SearchSuggestForm; ??
- ??
- public?class?SearchSuggestAction?extends?BasicDispatchAction?{ ??
- ??
- ????private?SearchSuggestDao?searchSuggestDao; ??
- ??
- ????public?void?setSearchSuggestDao(SearchSuggestDao?searchSuggestDao)?{ ??
- ????????this.searchSuggestDao?=?searchSuggestDao; ??
- ????} ??
- ??
- ????public?ActionForward?execute(ActionMapping?mapping,?ActionForm?form, ??
- ????????????HttpServletRequest?request,?HttpServletResponse?response) ??
- ????????????throws?Exception?{ ??
- ??
- ????????SearchSuggestForm?searchSuggestForm?=?(SearchSuggestForm)?form; ??
- ????????String?action?=?request.getParameter(