由于"Request method 'POST' not supported",休眠无法持久化对象



我遇到以下问题:

这是我的表单代码:

<form:form class="form-material validate-form" modelAttribute="Usuario_form" action="${pageContext.request.contextPath}/FormActionUser" method="POST" id="userForm">

这是我的控制器代码:

@RequestMapping(value = "/FormActionUser", method = RequestMethod.POST, params = "Crear")
  public ModelAndView CrearUsuario(HttpServletRequest request, HttpServletResponse response,
  @ModelAttribute("Usuario_form") Usuario usuario_form) {
    System.out.println("*****" + request.getMethod() + "*****");
    usuario_servicio.AgregarUsuario(usuario_form);
}

当然,System.out.println("*****" + request.getMethod() + "*****");的输出是*****POST*****

这是我的usuario_servicio.AgregarUsuario(usuario_form);代码:

public void AgregarUsuario(Usuario u) {
  Session session = this.sessionFactory.getCurrentSession();
  session.persist(u);
}

并且我得到了org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.logException Resolved exception caused by handler execution: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported错误。

通过POST请求发送表单时,请尝试发送csrf令牌。在表单中添加下一个输入:

<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>

最新更新