I'm hitting this issue regarding JSP not accepting PUT request. So I'm wondering how to fix it. I've read this related question in the stack overflow, but it doesn't explain how to fix it.
HTTP Status 405 - JSPs only permit GET POST or HEAD
Coming from Rails background, I'm trying to make it so I'm using the rails REST style like PUT for updates, and DELETE for deletes of the User resource.
But whenever there's an error in this controller it tries to return the request to the originating JSP but with Tomcat 8.0.9 isn't accepting the request and gives this error: "HTTP Status 405 - JSPs only permit GET POST or HEAD". I've tried disabling readonly in the Tomcat web.xml - it didn't have any effect and I still get the error. I've switched it to POST method and the flow works fine.
Is there a way to maybe force the forward to be POST method while still accepting PUT method for the request?
/**
* Edit a user account.
* @return the edit user view
*/
@RequestMapping(value = {"/update/{userId}"}, method = RequestMethod.PUT)
public String updateUser(@Valid @ModelAttribute("user") User user, BindingResult result, final RedirectAttributes redirectAttributes)
{
logger.debug(user);
// we check for duplicate email addresses during the update operation.
List<User> userCheckList = userRepository.findByEmail(user.getEmail());
if (userCheckList.size() > 0)
{
// size of list should only ever be 1
User userCheck = userCheckList.get(0);
if (userCheck.getId() != user.getId())
{
result.rejectValue("email", "error.user", "An account already exists for this user email address.");
}
}
if (result.hasErrors())
{
return "admin.users.edit";
}
// we locate the user and add it to the model
userRepository.save(user);
// the save operation was successful so we show the user message.
redirectAttributes.addFlashAttribute("user", user);
redirectAttributes.addFlashAttribute("message", "Updated successfully");
String viewName = "redirect:/admin/users";
logger.debug(viewName);
return viewName;
}