【问题标题】:spring mvc - HTML form passing request parameterspring mvc - HTML表单传递请求参数
【发布时间】:2020-07-09 06:11:39
【问题描述】:

我开始学习 Spring MVC 和 Web 开发。 我的控制器中有这个方法

@GetMapping("/deleteCar")
public String deleteCar(@RequestParam("carId") int carid) {
    carService.deleteCar(carid);
    return "redirect:/car/cars";
}

如何通过html表单传递请求参数?

<section>
    <form action="${pageContext.request.contextPath}/car/deleteCar">
    <input type="text" id="deleteCarWithID" value="${carId}">

    </form>
</section>

我收到此警告:

WARNING: Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required int parameter 'carId' is not present]

谢谢!

【问题讨论】:

    标签: java html forms spring-mvc


    【解决方案1】:

    您缺少名称属性,因此在输入字段中使用参数名称提及name 属性。试试下面的代码。还要添加一个提交类型按钮来提交表单。

    <input type="text" name="carId" id="deleteCarWithID" value="${carId}">
    

    【讨论】:

      猜你喜欢
      • 2011-07-05
      • 1970-01-01
      • 2015-11-18
      • 2015-07-31
      • 2016-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      相关资源
      最近更新 更多