1

I started to learn Spring MVC and web development. I have this method in my Controller

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

How can I pass the request parameter through html form ?

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

    </form>
</section>

I get this warning:

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

Thank you!

1 Answer 1

2

You are missing the name attribute so Mention name attribute with the parameter name in input field. Try below code for the same. Also add a submit type button to submit the form.

<input type="text" name="carId" id="deleteCarWithID" value="${carId}">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.