我正在我的网络应用程序中创建一个论坛。我有主页,其中显示所有主题和按钮以搜索和创建新线程。如果用户单击最后一个按钮,我会显示一个表单来输入新主题的数据。当用户单击提交时,我将这个新线程存储在 DB 中,然后重定向到显示主页的操作:
< action name="showForum" class="es.busco.colegio.actions.ForumAction" method="show">
< result name="success">/WEB-INF/jsp/forum.jsp< /result>
< /action>
< action name="newTopic" class="es.busco.colegio.actions.ForumAction" method="newTopic">
< result name="success">/WEB-INF/jsp/newTopic.jsp< /result>
< /action>
< action name="createTopic" class="es.busco.colegio.actions.Forumction" method="insert">
< result name="success" type="redirect">http://www.buscocolegio.com/Colegio/showForum.action< /result>
</ action>
问题是新主题在数据库和日志中插入了两次java.lang.IllegalStateException
当我调试时我看到执行服务调用而不是在 BD 中插入对象,程序执行回到方法的开头,这就是它被插入两次的原因:
try{
Date d=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String s=sdf.format(d);
Date d1=sdf.parse(s);
topic.setDate(d1);
topic.setText(topic.getText().replaceAll("\n", "<br>"));
topicService.createTopic(topic);
}catch (Exception ex){
logger.error("Error: "+ex,ex);
return Action.ERROR;
}
return Action.SUCCESS;
}
所以在执行 topicService.createTopic(topic); 它回到日期 d=new Date();
有人知道为什么吗???