从数据库里取出数据放到 select 但是还是实现连动连动的目的也是为了取 select 里的值做为条件再查询数据库里的记录

解决方案 »

  1.   

    唉!!这个问题还是ajax的问题啊,或者说是无刷新,或局部刷新的问题
      

  2.   

    如果LZ的这个操作不是很频繁的话,用AJAX吧。如果操作很频繁,用JS缓存一下输出,不每次都查数据库。
      

  3.   

    楼主可以写个javabean查找数据库结果放到list中,set到request中进行传递
    到jsp中去除进行迭代就行了
      

  4.   

    package com.sun.DAO.impl;import java.util.HashMap;
    import java.util.List;
    import java.util.Map;import org.hibernate.Query;
    import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import com.sun.DAO.CatagoryDAO;
    import com.sun.bean.Catagory;public class CatagoryDAOImpl extends HibernateDaoSupport implements CatagoryDAO { @SuppressWarnings("unchecked")
    public Map getCatagoryChild(int pid) {
    Query query = this.getSession().createQuery("from Catagory where pid = ?").setParameter(0,pid);
    List list = query.list();
    Map map = new HashMap();
    Catagory catagory = null;
    for(int i = 0 ;i < list.size();i++){
    catagory = (Catagory)list.get(i);
    map.put(catagory.getId(), catagory.getName());
    }
    return map;
    }
    @SuppressWarnings("unchecked")
    public Map getCatagoryP() {
    Query query = this.getSession().createQuery("from Catagory c where c.pid = 0");
    List list = query.list();
    Map map = new HashMap();
    Catagory catagory = null;
    for(int i = 0 ;i < list.size();i++){
    catagory = (Catagory)list.get(i);
    System.out.println(catagory.getId());
    map.put(catagory.getId(), catagory.getName());
    }
    return map;
    }}
    package com.sun.service.impl;import java.util.Map;import com.sun.DAO.CatagoryDAO;
    import com.sun.service.CatagoryService;public class CatagoryServiceImpl implements CatagoryService {

    private CatagoryDAO catagoryDAO;

    public CatagoryDAO getCatagoryDAO() {
    return catagoryDAO;
    } public void setCatagoryDAO(CatagoryDAO catagoryDAO) {
    this.catagoryDAO = catagoryDAO;
    } public Map getCatagoryChild(int pid) {
    return this.catagoryDAO.getCatagoryChild(pid);
    } public Map getCatagoryP() {
    return this.catagoryDAO.getCatagoryP();
    }}
      

  5.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script src="dwr/interface/JsCatagory.js"></script>
    <script src="dwr/engine.js" /></script>
    <script src="dwr/util.js" /></script>
    <script type="text/javascript">
    function loadChild(){
    JsCatagory.getCatagoryChild(dwr.util.getValue('maincatagory'),function(data){
    dwr.util.removeAllOptions("childcatagory");
    dwr.util.addOptions("childcatagory", data);
    });
    }
    function test(){
    JsCatagory.getCatagoryP(function(data){
    dwr.util.removeAllOptions("maincatagory");
    dwr.util.addOptions("maincatagory", data);
    });
    }
    </script> </head>
    <body onload="test();">
    <select id="maincatagory" onchange="loadChild();"></select>
    <select id="childcatagory"></select>
    </body>
    </html>
      

  6.   

      <convert converter="bean" match="com.sun.sendMessage.WebMessage" /> 
    - <create creator="spring" javascript="JsCatagory">
      <param name="beanName" value="catagoryService" /> 
      </create>
      <convert converter="bean" match="com.sun.bean.Catagory" />