使用Struts2时如何设置操作链接以从表中加载表中删除行 [英] How to setup an action link to delete the row from the table loaded from the table when using 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;
}
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.
推荐答案
我认为我看到了问题。问题在于操作中的属性 cid
是 null
(您可以执行 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屋!