[英]Struts2 CRUD Delete not Working
I am trying to delete a selected row in a project where I'm using Hibernate and Struts. 我正在尝试删除使用Hibernate和Struts的项目中的选定行。
<a href="DeletePublication?Id=<s:property value="Id"/>"><img
src="${pageContext.request.contextPath}/img/delete.png" width=20px
height=20px></a>
This is the Link I want to Click! 这是我要单击的链接! In the
struts.xml
the Action is defined as: 在
struts.xml
,动作定义为:
<action name="DeletePublication" class="de.nak.library.action.PublicationAction"
method="delete">
<result type="redirect">ShowPublicationList.action</result>
<result type="chain" name="input">ShowPublicationList</result>
</action>
The Action class looks like: Action类如下所示:
public String delete() {
publication = publicationService.loadPublication(publicationId);
if (publication != null) {
publicationService.deletePublication(publication);
}
return SUCCESS;
If I click the link, nothing is happening! 如果单击链接,则无任何反应! I tried to set a breakpoint in the
delete
method, and I saw that it is not even called. 我试图在
delete
方法中设置一个断点,但发现它甚至没有被调用。 Please help! 请帮忙!
Change this in the struts.xml
: 在
struts.xml
更改:
<constant name="struts.devMode" value="true" />
This will turn on a developer mode where you can see more log messages on the console. 这将打开开发人员模式,您可以在控制台上查看更多日志消息。 You might not have getter and setter for properties.
您可能没有属性的getter和setter。 Missing
"
in the attributes. 属性中缺少
"
。
<s:a namespace="onthepackage" action="DeletePublication"><s:param name="Id" value="%{Id}"/><img
src="<s:url value='/img/delete.png'/>" width="20px"
height="20px">
</s:a>
instead of using <a href="">
directly, use <s:url>
to get to the DeletePublication
action. 而不是直接使用
<a href="">
,而是使用<s:url>
进入DeletePublication
操作。 Then use that <s:url>
's reference to <a href='<s:property value="#ref"/>'
. 然后使用
<s:url>
对<a href='<s:property value="#ref"/>'
的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.