日期:2014-05-17  浏览次数:20833 次

DWR 问题 十万火急
package com.dao.DWR;

import java.util.List;

import org.hibernate.Query;

import com.bean.HibernateSessionFactory;
import com.bean.purchasingManagement.suppliers.Suppliers;


import org.hibernate.Session;
public class findSuppliers_sNumberDAO {
public String[] findSuppliersBysNumber(String name){
Session sess=HibernateSessionFactory.getSession();
String [] goodsname = null;
try {
String hql="select a from Suppliers a where a.sNumber like '"+name+"%' order by a.sCreationTime desc";
Query q=sess.createQuery(hql);
//q.setFirstResult(0);
//q.setMaxResults(8);
List list=q.list();
if(!list.isEmpty()){
List<Suppliers> g = list;
goodsname = new String [g.size()];
for (int i=0;i<list.size();i++) {
goodsname[i] = g.get(i).getSnumber(); //把商品名字放到数组里
}
}
 
} catch (Exception e) {
e.printStackTrace();
}finally{
HibernateSessionFactory.closeSession();
return goodsname;
}
}
}


dwr.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr//dwr30.dtd">
<dwr>
<allow>
  <create creator="new" javascript="findSuppliersBysNumber">
  <param name="class" value="com.dao.DWR.findSuppliers_sNumberDAO" />
  </create>
</allow>
</dwr>


JSP 界面

<script>
  function gog()
  {
  var keys = document.getElementById("suppliers.snumber").value;
   
  findSuppliersBysNumber.findSuppliersBysNumber(keys,call1);

  }
   
  function call1(data)  
  {
  if(data!=null){ //当查询结果没数据时,不写这句会报错的
  var keys = document.getElementById("suppliers.snumber").value;
  keys=keys.replace(/(^\s*)|(\s*$)/g,""); //这个是去掉空格,正则功能很强大的
  if(keys != ""){ //如果不判断,一按下键就会有8条数据
  document.getElementById("tishi").innerHTML = "";
  for(var i=0;i<data.length;i++){
  document.getElementById("tishi").innerHTML+="<div onclick=" + "document.getElementById('suppliers.snumber').value=this.innerText" + " onmouseout=" + "this.style.backgroundColor=''"+ " onmouseover=" + "this.style.backgroundColor='#3266CC'>" +data[i] + "</div>" ; //写这语句的时候小心,别写错了
   
  }
  }else{
  document.getElementById("tishi").innerHTML = "";
  } 
  }else{
  document.getElementById("tishi").innerHTML = "";
  }
   
  }
   
</script>

<table>
<tr>
  <input type="text" name="suppliers.snumber" id="suppliers.snumber" onkeyup="gog()" />
  </th>
  </tr>
  <tr>
  <td bgcolor="#F6F6EE"><div id="tishi" ></div></td>