gpt4 book ai didi

java - HTTP 状态 405 - 当我尝试更新数据库中的房间表时,不支持请求方法“POST”。当我选择要上传的图像时

转载 作者:太空宇宙 更新时间:2023-11-04 12:04:09 24 4
gpt4 key购买 nike

        <%@include file="../header.jsp" %>
<h1>Edit Room</h1>
<form action="save" method="post" enctype="multipart/form-data">
<div class="form-group">
<label>Room Type</label>
<input type="text" name="roomType" value="${Room.room_type}" required="required" class="form-control"/>
</div>
<div class="form-group">
<label>Room Description</label>
<input type="text" name="roomDescription" value="${Room.room_description}" required="required" class="form-control"/>
</div>

<div class="form-group">
<label>Room Number</label>
<input type="number" name="roomNumber" value="${Room.room_number}" required="required" class="form-control"/>
</div>
<div class="form-group">
<label>Room Image</label>
<input type="file" name="file" required="required" class="form-control"/>
</div>
<form:hidden path="ro_id" />
<div class="form-group">
<button type="submit" class="btn btn-success" >Save</button>
</div>
</form>
<%@include file="../footer.jsp" %>

我在执行 CRUD 时遇到错误。在名为“dispatcher”的 DispatcherServlet 中未找到带有 URI [/Hotels] 的 HTTP 请求的映射 警告:不支持请求方法“POST”

This is the Room controller

@ Controller @RequestMapping(value = "/admin/room")

    public class Roomcontroller {

@Autowired
private RoomService roomService;

@RequestMapping(method = RequestMethod.GET)
public String index(ModelMap map) throws SQLException {
map.addAttribute("Room", roomService.getAll());
return "admin/room/index";
}
@RequestMapping(value = "/addroom", method = RequestMethod.GET)
public String addRoom() throws SQLException {
return "admin/room/addroom";
}
@RequestMapping( value = "/editroom/{ro_id}", method = RequestMethod.GET)
public @ResponseBody ModelAndView edit(@PathVariable("ro_id") int ro_id) throws SQLException {
ModelAndView mv = new ModelAndView("admin/room/editroom");
mv.addObject("Room", roomService.getById(ro_id));
return mv;
}
@RequestMapping(value = "/deleteroom/{ro_id}", method = RequestMethod.GET)
public String delete(@PathVariable("ro_id") int ro_id) throws SQLException {
roomService.delete(ro_id);
return "redirect:/admin/room";
}
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String save(@RequestParam("roomType") String roomType,
@RequestParam("roomDescription") String roomDescription, @RequestParam("roomNumber") int roomNumber
,@RequestParam("file") MultipartFile multipartFile,HttpServletRequest req) throws SQLException, IOException {

Room room = new Room();
room.setRoom_type(roomType);
room.setRoom_description(roomDescription);
room.setRoom_number(roomNumber);

// TO DO : Save room, fetch the id of saved room and set it through
// setter in above object.

if(room.getRo_id()==0){

File roomImageDirectory = new File("D:\\Hotels\\uploadedImages");
if (!roomImageDirectory.exists()) {
roomImageDirectory.mkdirs();
}
String[] fileNameToken = multipartFile.getOriginalFilename().split("\\.");
// You can change file name to be saved.
String newFileName = "room-" + room.getRoom_number() + "." + fileNameToken[fileNameToken.length - 1];
File roomImage = new File(roomImageDirectory, "/" + newFileName);
roomImage.createNewFile();
multipartFile.transferTo(roomImage);
room.setImage(newFileName);

roomService.insert(room);
}
else
{
roomService.update(room);
}
return "redirect:/admin/room";
}
}

最佳答案

您输入的JSP的form action不正确,您需要更改如下:

<form action="/admin/room/save"  method="post" enctype="multipart/form-data">

关于java - HTTP 状态 405 - 当我尝试更新数据库中的房间表时,不支持请求方法“POST”。当我选择要上传的图像时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40583369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com