【问题标题】:Spring Controller accepts duplicate requestsSpring Controller 接受重复请求
【发布时间】:2019-11-19 12:51:01
【问题描述】:

每当我向服务器发送请求时,它都会在 url 中输入重复的条目。

详细说明请看下面的例子。

 @Controller
 @RequestMapping("v")
 public class ControllerDemo{

  @RequestMapping("test")
  public String view()
 {
    return "index.jsp";
 }

@RequestMapping("view")
public String view()
{
   return "login.jsp";
}
   }

第一次请求Url:Https:localhost:8080/v/test 当我从 test.jsp 发出不同的请求时,它会执行以下模式 Https:localhost:8080/v/v/view


在Test.jsp中

    <form action="v/view">
       //Some data and submit
    </form>

它将在 url: https:localhost:8080/v/v/view 中发送请求,而不是 localhost:8080/v/view

如果您需要任何其他信息或项目配置,请告诉我。

【问题讨论】:

    标签: spring spring-boot jsp


    【解决方案1】:

    从问题本身来看,action 标签的值似乎被附加到当前页面的路径中,所以https:localhost:8080/v + v/view = https:localhost:8080/v/v/view。

    解决方案:改为&lt;form action="view"&gt;

    这得到了action=""points to the current page.这一事实的支持

    【讨论】:

    • 谢谢,我搞砸了。如果我们想要处理不同的请求,这样它就不会附加现有链接,创建一个新请求,例如从 localhost:8080/v/view 到 localhost:8080/user/my_account。有时小错误会让你搞砸 LOL
    猜你喜欢
    • 2017-10-02
    • 1970-01-01
    • 1970-01-01
    • 2019-05-10
    • 2017-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-18
    相关资源
    最近更新 更多