请教个问题:   在一个jsp中我实现查询和删除功能,即查询之后 把查询显示在一个列表里,点击复选框选择要删除的记录! 基于struts+hibernate  怎么实现?谢谢(主要是action那怎么用)  问:可否使用一个form来实现. 或者加个动态form.谢谢各位大虾!!!感激///

解决方案 »

  1.   

    你需要用checkbox的集合来记录你的主键id。如果有分页就需要在session中记录这个集合。可以考虑使用ajax来给checkbox集合增加或减少id。例如你在session中定义了一个Collection col;
    然后每次点击某个checkbox的时候,就激发一个javascript来调用ajax,完成对集合的add和remove。当点击删除按钮时,就可以循环session中的这个集合,得到id,来删除相应的记录。
      

  2.   

    在form中设置该属性的数组 即可获取到checkbox的多选值
      

  3.   

    给你一段我用过的程序,看懂之后,依葫芦画瓢就OK了.
    这部分是struts的Action根据url所带的参数action是"add/edit/delete"分别调用BO(就是业务BEAN,负责操作数据库的)里的方法来干活.
    最后导航到需要的页面去.
    public class VideoInfoAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                throws IOException, ServletException {
            //这里进行权限的判断
            HttpSession session = request.getSession();
           //这里对用户合法性进行校验
           ReturnInfo retValiate = OperatorRightBO.validate(request);
           User user = null;
           
           if(retValiate != null && retValiate.isFlag()){
               user = (User)session.getAttribute(User.SESSION_KEY);
           }else{
               //校验没有通过,返回到一个指定也页面
               FileLog.debugLog("validatesesson return=" + retValiate.getInfo());
               return mapping.findForward("loginFaile");
           }
           
           VideoInfoFormBean formbean = (VideoInfoFormBean)form;
           String action  =  formbean.getAction();       
           if(action !=null && action.equals("videolist")){//视频资源树
            VideoInfoBo bo =  new VideoInfoBo();
            request.setAttribute("classtree",bo.getInfoCheckTreeScript());
    return mapping.findForward("classlist");
           }else if(action !=null && action.equals("showaddview")){//显示增加页面
            request.setAttribute("info",WordBo.getGameId());
            formbean.setParent_code(formbean.getId());
    return mapping.findForward("addview");
           }else if(action !=null && action.equals("addinfo")){//增加图片
    ResourceBundle rb = ResourceBundle.getBundle("webpage");
    String address = rb.getString("page.videoinfo");//获取服务器存放视频路径
    String top = rb.getString("top.video");
    VideoInfoBo bo =  new VideoInfoBo();
    ReturnInfo reinfo = bo.addPhotoInfo(address,top,formbean,user);
    if(reinfo.isFlag()){
    request.setAttribute("url","VideoInfoAction.do?action=videolist");
    request.setAttribute("info","增加视频成功!");
    return mapping.findForward("success");
    }else{
    request.setAttribute("info",reinfo.getInfo());
                return mapping.findForward("fail");
    }
    }else if(action !=null && action.equals("geticon")){//显示图标树
    String id = null;
    if(formbean.getIcon() != null && formbean.getIcon().length() > 0)
    id = formbean.getIcon();

    PhotoInfoBo bo = new PhotoInfoBo();
    request.setAttribute("classtree",bo.getInfoCheckTreeScript(id));
    return mapping.findForward("geticon");
    }else if(action !=null && action.equals("getaction")){//获取活动树
    String id = null;
    if(formbean.getAction_id() != null && formbean.getAction_id().length() > 0)
    id = formbean.getAction_id();

    WordInfoBO bo = new WordInfoBO();
    request.setAttribute("classtree",bo.getActionInfoRadioTreeScript(id));
    return mapping.findForward("getaction");
    }else if(action !=null && action.equals("showupdate")){
    request.setAttribute("ginfo",WordBo.getGameId());
    VideoInfoBo bo = new VideoInfoBo();
    request.setAttribute("info",bo.getInfo(formbean.getId()));
    return mapping.findForward("updateview");
    }else if(action !=null && action.equals("doupdate")){
    if(CheckOperatorRight.checkRight(user,"video_info",formbean.getId(),CheckOperatorRight.updateUser,CheckOperatorRight.updatetime)){

    VideoInfoBo bo = new VideoInfoBo();
    ReturnInfo reinfo = bo.updateInfo(formbean,user);
    if(reinfo.isFlag()){
    request.setAttribute("url","VideoInfoAction.do?action=videolist");
    request.setAttribute("info","修改视频成功!");
    return mapping.findForward("success");
    }else{
    request.setAttribute("info",reinfo.getInfo());
                return mapping.findForward("fail");
    }
    }else{
    request.setAttribute("info","无法修改该资源");
                return mapping.findForward("fail");
    }

    }else if(action !=null && action.equals("delete")){
    VideoInfoBo bo = new VideoInfoBo();
    ReturnInfo reinfo = bo.deleteInfo(formbean.getClasscheck(),user);
    if(reinfo.isFlag()){
    request.setAttribute("url","VideoInfoAction.do?action=videolist");
    request.setAttribute("info","删除视频成功!");
    return mapping.findForward("success");
    }else{
    request.setAttribute("info",reinfo.getInfo());
                return mapping.findForward("fail");
    }
    }
           return mapping.findForward("");
    }
    }
      

  4.   

    谢谢各位!
    1楼提到用ajax,我不太了解这个!所以不知道怎么用!正打算学习一下,呵呵!不过我的问题还没有解决,  我的问题不是jsp显示,
       是在同一个jsp中,查询后 显示出来 再进行删除!
     回3楼, 我用dispatchAction实现  或者用lookupdispatchAction。 就是说一个jsp 页面 涉及两个request,一个是查询,一个是删除。
      

  5.   

    在ActionForm添加一个对应CheckBox的数据就可以,CheckBox的value记录id,提交后,当Action判断为删除时,从数组里取得要删除id的列表。
      

  6.   

    在ActionForm添加一个对应CheckBox的数组就可以,CheckBox的value记录id,提交后,当Action判断为删除时,从数组里取得要删除id的列表。
      

  7.   

    谢谢各位,问题已经解决!!! 我用的是lookupdispatchAction实现的!!