Struts 1 Ajax调用处理两次

时间:2012-01-30 22:33:48

标签: ajax struts-1

我有一个Struts 1应用程序,它使用一点点Ajax来创建和删除应用程序中的一些对象。对于创建和删除操作,当浏览器发布操作时,服务器将对其进行两次处理。

这是浏览器两次发布ajax的情况。我使用Paros代理工具确认浏览器只发送了一次ajax请求,但我的动作类仍然被调用两次。

使用Eclipse我设置了一个调试断点,并注意到每次通过我的动作类时调用堆栈都不一样。

第一次通过我

MyActionClass.getDisplayPage(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) line: 65   
MyActionClass(Action).execute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) line: 224 
ExecuteAction.execute(ActionContext, Action, ActionConfig, ActionForm) line: 53 
ExecuteAction(AbstractExecuteAction).execute(ActionContext) line: 64    
ExecuteAction(ActionCommandBase).execute(Context) line: 48  
ChainBase.execute(Context) line: 190    
LookupCommand.execute(Context) line: 304    
ChainBase.execute(Context) line: 190    
ComposableRequestProcessor.process(HttpServletRequest, HttpServletResponse) line: 280   
ActionServlet.process(HttpServletRequest, HttpServletResponse) line: 1858   
ActionServlet.doPost(HttpServletRequest, HttpServletResponse) line: 459 

我得到第二遍(额外的行标有***

MyActionClass.getDisplayPage(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) line: 65   
***MyActionClass.unspecified(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) line: 199  
***MyActionClass(DispatchAction).dispatchMethod(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse, String) line: 242   
***MyActionClass(DispatchAction).execute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) line: 167  
***MyActionClass(Action).execute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) line: 217  
ExecuteAction.execute(ActionContext, Action, ActionConfig, ActionForm) line: 53 
ExecuteAction(AbstractExecuteAction).execute(ActionContext) line: 64    
ExecuteAction(ActionCommandBase).execute(Context) line: 48  
ChainBase.execute(Context) line: 190    
LookupCommand.execute(Context) line: 304    
ChainBase.execute(Context) line: 190    
ComposableRequestProcessor.process(HttpServletRequest, HttpServletResponse) line: 280   
ActionServlet.process(HttpServletRequest, HttpServletResponse) line: 1858   
ActionServlet.doPost(HttpServletRequest, HttpServletResponse) line: 459 

除了明显的差异外,调用堆栈是相同的。

以下是与此帖子相关的struts配置操作

<action path="/myAjaxRequest"
  type="com..example.MyActionClass"
  name="myActionForm"
  parameter="save">
</action>

有没有人知道第二次传球的来源是什么?我不知道从哪里开始看。

1 个答案:

答案 0 :(得分:0)

原来这种行为是由&#34;功能&#34;申请。设计应用程序的任何人都会覆盖DispatchAction.execute()方法。当从动作类接收空ActionForward时,重写的execute()方法将尝试使用不同的调用路径再次调用该动作。

由于我的操作是为ajax请求提供服务,因此在成功执行后它会故意返回null。结果是我的动作被execute()方法再次调用,请求将被第二次处理。