0

I have a problem with checkbox. I have such jsp page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>All Photos</title>
</head>
<body>
    <form action="/photos/deletePhotos">
    <c:forEach var="photo" items="${photoList}">
        <p><input type="checkbox" name="id" value="${photo.key}">${photo.key}</p>
        <img src="/photos/photo/${photo.key}" width="300" height="200">
        <br/><br/>
    </c:forEach>
    <input type="submit" value="Delete" />
    </form>

</body>
</html>

and such controller:

@RequestMapping("/deletePhotos")
    public ModelAndView deleteSomePhotos(@PathVariable(name = "id", required = false) long[] id) {
        System.out.println(id);
        return new ModelAndView("all", "photoList", photos);
    }

problem is id==null, no matter checked checkbox or not. Where is my mistake?

1 Answers1

0

@PathVariable is for path variable, like @RuquestMapping("/deletePhotos/{id}").
Use @RequestParam instead of @PathVariable.

Refer here : @RequestParam vs @PathVariable

Min Hyoung Hong
  • 1,102
  • 9
  • 13