使用struts2时如何设置操作链接以删除从表中加载的表中的行 [英] How to setup an action link to delete the row from the table loaded from the table when using struts2

查看:23
本文介绍了使用struts2时如何设置操作链接以删除从表中加载的表中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从存储在数据库中的表中永久删除一行,该表正在显示在 jsp 页面上.我有一个链接 Delete(对于每一行),只需单击一下即可删除该行.

I want to delete a row persistently from a table stored in the database which is being displayed on the jsp page. I have a link Delete (for each row) to delete the row on a single click.

我的jsp代码是:

    <s:iterator value="topperList" >
      <tr>
         <td><s:property value="uid"/></td>
         <td><s:property value="name"/></td>
         <td><s:property value="password"/></td>
         <td><s:property value="sex" /></td>
         <td><s:property value="age" /></td>
         <td><s:property value="city" /></td>
         <td><s:property value="abuse" /></td>
         <td><s:property value="lastlogin" /></td>
         <td><s:property value="points" /></td>
         <td><s:property value="joined" /></td>
         <td><s:property value="email" /></td>
         <s:url id="url" action="delete" >
           <s:param name="uid"><s:property value="uid" /></s:param>
         </s:url>
         <td><s:a href="%{url}">Delete</s:a></td>
      </tr> 
  </s:iterator>

我的动作类代码是:

private Integer uid;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}
public String delete() {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Users user = (Users) session.load(Users.class, this.getUid());
        if (null != user) {
            session.delete(user);
        }
        session.getTransaction().commit();
           return SUCCESS;
    }

struts.xml 中的动作代码:

action code in struts.xml :

<action name="delete" class="com.rambo.action.FindToppers" method="delete" >
        <result name="success">buser.jsp</result>
    </action>

但我得到了错误:

org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [beans.Users#0]

我看到表 USERS 中有一个适当的行,uid=56.但它显示没有具有标识符的行存在.但是我没有收到任何服务器错误日志.有人能指出可能是什么问题吗?

I have seen there is a proper row in table USERS with uid=56. But it shows No row with the identifier exists. However i am not getting any server error logs. Can some one point out what can be the problem.

推荐答案

我想我看到了问题所在.问题是动作中的属性cidnull(你可以做一个System.out.println(cid)).如果 null 被打印,您可能必须使用 ParameterAware 来捕获 url 参数.

I think I see the problem. The problem is that the attribute cid in the action is null (you can do a System.out.println(cid)). If null is printed probably you will have to catch the url parameters with ParameterAware.

这篇关于使用struts2时如何设置操作链接以删除从表中加载的表中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆