如何防止 Apache 服务器在 Java 的 GET 请求上被多次触发。

huangapple go评论88阅读模式
英文:

How to prevent apache server to be hitting twice on a java get request

问题

我正在使用一个apache tomcat服务器,在进行项目时,我所有的GET请求方法都会被调用两次,而不需要手动发起调用。如果我调用一个方法,在其返回后,该方法会自动被再次调用。我已经尝试了许多方法,但都没有帮助。这个项目与另一个正常工作的项目是完全相同的副本,然而旧项目运行良好。

我尝试了以下几种策略,但都没有解决我的问题:

  1. https://www.niceonecode.com/Question/20307/MVC-Controller-Action-Gets-Called-Multiple-Times

  2. https://stackoverflow.com/questions/36325529/spring-controller-method-called-twice/36679031#36679031

我还验证了是否有任何脚本发起了第二次调用,但没有这样的脚本。

有谁能帮助我解决这个问题吗?

我的方法的示例代码:

@RequestMapping(value = "/method/test/{id}/{name}", method = RequestMethod.GET)
public String getTestMethod(@PathVariable int id, @PathVariable String name, Model model, HttpServletRequest request, HttpServletResponse response, RedirectAttributes ra)
{
    System.out.println("success");
    return "success";
}
英文:

I'm using an apache tomcat server, on doing a project all my get request methods are hitting twice without initiating the call manually. If i call a method, on its return the method is being called again automatically. I have tried many ways but it doesn't helps me. This project is a same copy of another working project, however the old project is working fine.

I have tried these following answers, but this couldn't solve my problem

  1. https://www.niceonecode.com/Question/20307/MVC-Controller-Action-Gets-Called-Multiple-Times

  2. https://stackoverflow.com/questions/36325529/spring-controller-method-called-twice/36679031#36679031

I have also verified if any of my scripts is initiating the second call, but there is no scripts like that.
Can anyone helps me out?

Sample code of my method

@RequestMapping(value = "/method/test/{id}/{name}", method = RequestMethod.GET)
public String getTestMethod(@PathVariable int id, @PathVariable String name, Model model, HttpServletRequest request, HttpServletResponse response, RedirectAttributes ra)
{
System.out.println("success");
return "success";
}

答案1

得分: 1

我遇到了同样的问题。然后我在我的index.html文件中将href="Favicon.ico"更改为空。然后它起效了。将它改为href=""

英文:

I had the same problem. Then I have changed href="Favicon.ico" to empty in my index.html file. Then it worked. Change it to href="".

huangapple
  • 本文由 发表于 2020年5月4日 16:37:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/61588159.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定