<tr>       
             <td colspan="5" class="STYLE1"> <a href="excel651.jsp" class="STYLE7 STYLE9">保存查询信息到EXCEL </a> </td>          
           </tr> 
这部分是没用的,是我前面做的尝试,失败了

解决方案 »

  1.   

    这是调用显示页面的actionpublic ActionForward selectAgent(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
          WebForm2 webf = (WebForm2)form;//从页面获得表单数据,强制转化为WebForm2    
            String Agent = webf.getAgent();
            String Area = webf.getArea();
            String Ip = webf.getIp();
            String Tel = webf.getTel();
            String hql = "from Agent where";
            if(Area.trim().length()!=0)
             {hql=hql+" area like '%" + Area + "%'";         
              if(Agent.trim().length()!=0)
                 {hql=hql+"and agent like '%" + Agent + "%'";}
              if(Ip.trim().length()!=0)
                 {hql=hql+"and ip like '%" + Ip + "%'";}
              if(Tel.trim().length()!=0)
                 {hql=hql+"and tel like '%" + Tel + "%'";}
             }
            else {System.out.println("所属区域不能为空!");};//查询数据的SQL
    Session session = HibernateSessionFactory.getSession();//获得数据库的连接
    Query query = session.createQuery(hql);//运行查询
    Iterator iterate = query.iterate();//把查询的结果转换成迭代器

    ArrayList list = new ArrayList();//存放从数据库中的记录转变成页面的form
    while(iterate.hasNext()){//循环
             WebForm2 webform3 = new WebForm2();  
    Agent agent = (Agent)iterate.next();
    webform3.setAgent(agent.getAgent());
    webform3.setTerminal(agent.getTerminal());
    webform3.setIp(agent.getIp());
    webform3.setAccessnumber(agent.getAccessnumber());
    webform3.setName(agent.getName());
    webform3.setTel(agent.getTel());
    webform3.setSeq(agent.getSeq());
    webform3.setArea(agent.getArea());
    webform3.setMemo(agent.getMemo());
    list.add(webform3);


    }
    session.close();//关闭数据库连接
    request.setAttribute("list", list);//把数放到request中,这样页面就可以获得了
    return mapping.findForward("display");//还记得我们struts-cfg.xml里面的内容吗,这个就直接跳转到展示页面

    }