我遇到了有關JSP不接受PUT請求的問題。所以我想知道如何解決它。我已經在堆棧溢出中讀過這個相關的問題,但並沒有解釋如何解決它。405 Put方法的JSP錯誤
HTTP Status 405 - JSPs only permit GET POST or HEAD
從Rails的背景來了,我想使它所以我使用的鐵軌REST風格就像放更新和刪除用戶資源的刪除。
但是,無論何時在此控制器中出現錯誤,它都會嘗試將請求返回到始發JSP,但是Tomcat 8.0.9不接受請求並且出現此錯誤:「HTTP狀態405 - JSP只允許GET POST或頭」。我試過在Tomcat web.xml中禁用readonly - 它沒有任何效果,我仍然得到錯誤。我已將它切換到POST方法,並且流程正常工作。
有沒有辦法強制轉發爲POST方法,同時仍然接受請求的PUT方法?
/**
* 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;
}
這可能會幫助你http://www.codereye.com/2010/12/configure-tomcat-to-accept-http-put.html – mahesh
謝謝我已經嘗試過,但它沒有任何效果,相同錯誤發生。 –