简体   繁体   English

Struts2 Action被调用两次

[英]Struts2 Action called twice

I am calling struts action like 我叫struts动作像

<a href="someactionLink.action">Do action</a>

In Struts.xml 在Struts.xml中

<action name="*Link" method="{1}" class="com.shashi.getalldata.LinkAction">

The problem is the action called twice. 问题是该动作被调用了两次。 Once when i click the href and second time while page loading. 一次,当我单击href时,第二次在页面加载时。 Do any one have any idea on what's the case here? 有人对这里的情况有任何想法吗?

Do you have anything on the page that could result in a subsequent request? 页面上是否有任何内容可能导致后续请求? Eg favicon/stylesheet/image/script. 例如favicon / stylesheet / image / script。 By favicon, I mean lack of, but the browser might be looking (most browsers only look in one place for them). 所谓的Favicon,是指缺少浏览器,但浏览器可能正在寻找它们(大多数浏览器只在一个地方寻找它们)。

Check the access logs for a subsequent request. 检查访问日志是否有后续请求。

Take a look at this link. 看一下这个链接。 It helped me figure out my issue with a double submit. 它帮助我通过两次提交来解决我的问题。 It had nothing to do with my code, it was completely YSlow plug-in for FireFox 3.X and 4.X. 它与我的代码无关,它完全是FireFox 3.X和4.X的YSlow插件。

Double submit solution 双重提交解决方案

Solution to my double submit issue. 解决我的双重提交问题。

first off: I was doing a form submit using javascript. 首先,我正在使用javascript进行表单提交。 Like: 喜欢:

<a href="#" onclick="save();">
      <input type="image" src="images/save.gif" alt="Save" title="Save" /></a>

where save() was: save()在哪里:

function save() {
     ...
     document.form_name.action = "Struts2_action.action";
     document.forms[1].submit(); 
   }

Well I was NOT adding "return false;" 好吧,我没有添加“ return false”; after save() to do the following: 在save()之后执行以下操作:

Return false follow three steps 返回false,请遵循三个步骤

  • First It stops the browsers default behaviour. 首先,它停止了浏览器的默认行为。
  • It prevents the event from propagating the DOM 它防止事件传播DOM
  • Stops callback execution and returns immediately when called. 停止回调执行,并在调用后立即返回。

So, my anchor became: 因此,我的主播成为:

<a href="#" onclick="save();return false;">
          <input type="image" src="images/save.gif" alt="Save" title="Save" /></a>

and the double submit problem was resolved. 双重提交问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM