首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

关于struts+hibernate中的查询和删除有关问题

2011-12-02 
关于struts+hibernate中的查询和删除问题请教个问题:在一个jsp中我实现查询和删除功能,即查询之后把查询显

关于struts+hibernate中的查询和删除问题
请教个问题:

      在一个jsp中我实现查询和删除功能,即查询之后   把查询显示在一个列表里,点击复选框选择要删除的记录!   基于struts+hibernate     怎么实现?谢谢(主要是action那怎么用)

  问:可否使用一个form来实现. 或者加个动态form.

谢谢各位大虾!!!感激///


[解决办法]
你需要用checkbox的集合来记录你的主键id。如果有分页就需要在session中记录这个集合。

可以考虑使用ajax来给checkbox集合增加或减少id。

例如你在session中定义了一个Collection col;
然后每次点击某个checkbox的时候,就激发一个javascript来调用ajax,完成对集合的add和remove。

当点击删除按钮时,就可以循环session中的这个集合,得到id,来删除相应的记录。
[解决办法]
在form中设置该属性的数组 即可获取到checkbox的多选值
[解决办法]
给你一段我用过的程序,看懂之后,依葫芦画瓢就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( " ");
}
}

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

热点排行