摘要:
在项目的实际应用中用到了jquery-autocomplete插件。原因:下拉框不能自动分页,数据量很大,而jquery-autocomplete组件就能解决此问题。能提供百度一样的搜索,也能设定记录数。默认是10条。
jsp页面代码:
<script type="text/javascript">
$(document).ready(function(){
$("#s_com_name").focus(function(){
$("#s_com_name").autocomplete("bysgl?task=list_TB_KHGL_COMPANY_Com_num_AutoComplete", {
keyId:"s_com_number",
width: 260,
selectFirst: false
}).result(function(event, data, formatter) {//重新刷新当前页面
//alert(data);
form1.com_number.value=data;
form1.action="Xcsb";
form1.task.value="addTB_XCGL_Xcsb";
form1.submit();
});
});
});
</script>
Java代码:
String college_name=new String(request.getParameter("q").getBytes("iso8859-1"),"utf-8");//通过q获取参数
String sqlwhere = "";
college_name=StringUtil.nvl(college_name, "");
college_name=StringUtil.trim(college_name);
sqlwhere = " where entername_var like '%" + college_name + "%'";
dl_d_entercustomerPO po = new dl_d_entercustomerPO();
po.setWhereClause(sqlwhere);
oa_d_entercustomerSer ser = new oa_d_entercustomerSer();
bjepn.base.util.Result rs = ser.listdl_d_entercustomerPO(po);
StringBuffer buffer = new StringBuffer(5000);
if (rs != null && rs.getAllBeans() != null
&& rs.getAllBeans().length > 0) {
ESSBean beans[] = rs.getAllBeans();
for (int i = 0; i < beans.length; i++) {
po = (dl_d_entercustomerPO) beans[i];
buffer.append(po.getEntername_var()).append("|").append(
po.getGuid()).append("\n");//不知道是否一定要用|符号,按照这样的格式返回数据
}
}
// response.getWriter().write("xiao\nhaibing\n");
response.getWriter().write(buffer.toString());