为了避免重新提交表单,我使用了POST-Redirect- GET模式,它可以正常工作。现在,在我的注册页面(成功页面)上,显示了ActionMessage“已成功插入审阅!”。当用户刷新页面时,我要删除此消息。
我在JSP页面上的代码:
<s:if test="hasActionMessages()"> <div class="success-mesg" id="success-mesg"> <s:iterator value="actionMessages"> <s:property value="top" /> </s:iterator> </div> </s:if>
在struts.xml上:
<action name="insertReview" class = "com.tenkinfo.streamlinedmapnsav.ui.action.WriteReviewAction" method="insertReview" > <result name="insertReviewDone" type="redirect" >insertReviewDone</result> <result name="input" type="tiles">display.writeReview.page</result> </action> <action name="insertReviewDone" class = "com.tenkinfo.streamlinedmapnsav.ui.action.WriteReviewAction" method="insertReviewDone" > <result name="success" type="tiles" >display.writeReview.page</result> </action>
在动作课中:
public String insertReviewDone(){ addActionMessage("Write review is successful"); return "success"; }
编辑:
实施Aleksandr M建议的答案后,我遇到以下问题:
<s:form name="insertReview" action="insertReview" id="insertReview" theme="simple" enctype="multipart/form-data"> <div class="content-area"> <h1> Review <s:property value="businessName" /> </h1> <s:if test="hasActionMessages()"> <div class="success-mesg" id="success-mesg"> <s:iterator value="actionMessages"> <s:property value="top" /> </s:iterator> </div> </s:if>
刷新以上代码中的页面后,businessName将被删除并且不显示。任何帮助将不胜感激。
用于Message Store Interceptor在您的操作中存储操作消息insertReview并在您的insertReviewDone操作中检索它。insertReview返回insertReviewDone结果时,在方法中添加操作消息。
Message Store Interceptor
insertReview
insertReviewDone
也可以使用redirectActionresult重定向到action而不是redirect。
redirectAction
redirect
<action name="insertReview" class = "com.tenkinfo.streamlinedmapnsav.ui.action.WriteReviewAction" method="insertReview"> <interceptor-ref name="store"> <param name="operationMode">STORE</param> </interceptor-ref> <interceptor-ref name="defaultStack" /> <result name="insertReviewDone" type="redirectAction">insertReviewDone</result> <result name="input" type="tiles">display.writeReview.page</result> </action> <action name="insertReviewDone" class = "com.tenkinfo.streamlinedmapnsav.ui.action.WriteReviewAction" method="insertReviewDone" > <interceptor-ref name="store"> <param name="operationMode">RETRIEVE</param> </interceptor-ref> <interceptor-ref name="defaultStack" /> <result name="success" type="tiles">display.writeReview.page</result> </action>