弹簧,不支持请求方法“开机自检”[已关闭]

2022-09-01 17:20:18

首先说道歉问这个重复的问题。

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

这是我的用户.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
@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";
    }
}

Problem是当我们是 点击 按钮 在 ,服务器控制台中没有响应,但下面显示警告消息:Addprofessional.jsp

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

为什么会出现此警告?我已经指定了方法=“POST”。

请帮忙..


答案 1

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

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

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


答案 2

您的用户.jsp:

 <form:form action="profile/proffesional" modelAttribute="PROFESSIONAL">
     ---
     ---
    </form:form>

在控制器类中:

(使其成为一个有意义的完整方法名称。听到我认为你在DB中插入记录。

@RequestMapping(value = "proffessional", method = RequestMethod.POST)
    public @ResponseBody
    String proffessionalDetails(
            @ModelAttribute 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";

    }