gpt4 book ai didi

java - Spring,请求方法 'POST' 不支持

转载 作者:IT老高 更新时间:2023-10-28 13:50:07 26 4
gpt4 key购买 nike

首先说抱歉问这个重复的问题..

实际上在我的 spring 应用程序中,我有 user.jspprofessional.jsp

这是我的 User.jsp:

  <form:form action="profile/user" modelAttribute="profile">
<div>
<jsp:include page="professional.jsp"></jsp:include>
</div>

</form:form>

这是我的专业.jsp:

   <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<fieldset id="profile_proffiesional">
<form:form action="profile/proffiesional" modelAttribute="PROFESSIONAL" method="POST">
<p>
<label for="position">Position</label>
<form:input path="position" tabindex="4" />
</p>
<p>
<label for="location">Location</label>
<form:input path="location" tabindex="5" />
</p>
<p>
<label for="description">Description</label>
<form:input path="description" tabindex="5" />
</p>
<p>
<input type="submit" value="Add">
</p>
</form:form>
</fieldset>

这是我的 Controller 类:

    @Controller
@RequestMapping(value = "profile")
public class UserProfileController {

@Autowired
private UserService userService;

@Autowired
private SessionData sessionData;

@RequestMapping(value = "user", method = RequestMethod.GET)
public String user(Model model) throws Exception {
model.addAttribute("PROFESSIONAL", new UserProfessionalForm());
model.addAttribute("EDUCATIONAL", new UserEducationalForm());
model.addAttribute("AWARDS", new UserAwardsForm());
return "profile/user";
}

@RequestMapping(value = "proffessional", method = RequestMethod.POST)
public @ResponseBody
String forgotPassword(UserProfessionalForm professionalForm,
BindingResult result, Model model) {

UserProfileVO userProfileVO = new UserProfileVO();
userProfileVO.setUser(sessionData.getUser());
userService.saveUserProfile(userProfileVO);
model.addAttribute("professional", professionalForm);
return "Your Professional Details Updated";
}
}

问题是当我们点击professional.jsp中的Add按钮时,服务器控制台没有响应,但显示以下警告消息:

  29 Mar, 2013 1:03:51 PM org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleHttpRequestMethodNotSupported
WARNING: Request method 'POST' not supported

为什么会出现这个警告?我已经指定了method="POST"..

请帮忙..

最佳答案

我在我的 sprint 安全 xml 文件中启用了 csrf,所以我只在表单中添加了一行:

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

通过这种方式,我能够提交具有 model 属性的表单。

关于java - Spring,请求方法 'POST' 不支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15699350/

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