Help please solve the problem

jsp

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <c:if test="${currentRoom.getLight()}"> <form method="post" action="/room/allroom/"> <input type="radio" name="status" value="turnOff"> <button type="submit">Выключить</button> </form> </c:if> <c:if test="${!currentRoom.getLight()}"> <form method="post" action="/room/allroom/"> <input type="radio" name="status" value="turnOn"> <button type="submit">Включить</button> </form> </c:if> </body> 

Controller

 @Controller @RequestMapping(path = "/room") public class RoomController { @GetMapping(path = "allroom/{roomNumber}") public ModelAndView getRoomById(@PathVariable("roomNumber") Integer roomNumber, ModelAndView modelAndView, HttpServletRequest httpServletRequest){ modelAndView.setViewName("currentRoom"); List<Room> roomList = roomService.allListRooms(); Room room = roomList.get(roomNumber); httpServletRequest.getSession().setAttribute("currentRoom", room); return modelAndView; } @PostMapping(path = "allroom/{roomNumber}") public ModelAndView light(@PathVariable("roomNumber") Integer roomNumber, @RequestParam("status") String status, ModelAndView modelAndView, HttpServletRequest httpServletRequest){ modelAndView.setViewName("currentRoom"); if(status.equals("turnOn")){ roomService.lightOn(roomNumber); return modelAndView; } if(status.equals("turnOff")){ roomService.lightOff(roomNumber); return modelAndView; } return modelAndView; } 

Error: Message Request method 'POST' not supported

It is not supported by the target resource.

    1 answer 1

    You submit the link action = "/ room / allroom /", although two "/ room / allroom / {roomNumber}"

    Add a number to the link. To request sent to "/ room / allroom / 1" say. Or remove {roomNumber} from the controller