ASR
ASR

Reputation: 3549

Spring MVC form giving HTTP Status 400

I am getting HTTP status 400. The request sent by the client was syntactically incorrect. What I am doing is, just saving edit form into database, but request not going to saveApplication method.

The following is my edit.jsp:

<div align="center">
        <h1>New/Edit Contact</h1>
        <form:form action="saveApplication" method="post" modelAttribute="application">
        <table>
            <form:hidden path="applicationId"/>
            <tr>
                <td>Application Name:</td>
                <td><form:input path="applicationName" /></td>
            </tr>
            <tr>
                <td>Start Date:</td>
                <td><form:input path="startDate" id="startDate"/></td>
            </tr>
            <tr>
                <td>End Date:</td>
                <td><form:input path="endDate" id="endDate"/></td>
            </tr>
            <tr>
                <td>Projected StartDate:</td>
                <td><form:input path="projectedStartDate" id="projectedStartDate"/></td>
            </tr>
            <tr>
                <td>Projected EndDate:</td>
                <td><form:input path="projectedEndDate" id="projectedEndDate"/></td>
            </tr>
            <tr>
                <td>Current Action:</td>
                <td><form:input path="currentAction" /></td>
            </tr>

            <tr>
                <td>Comments:</td>
                <td><form:input path="comments" /></td>
            </tr>
            <tr>
                <td colspan="2" align="center"><input type="submit" value="Save"></td>
            </tr>
        </table>
        </form:form>
    </div>

The following are methods in my controller class:

    @RequestMapping(value = "/editApplication", method = RequestMethod.GET)
    public ModelAndView editApplication(HttpServletRequest request) {

        ModelAndView model = new ModelAndView();
        int applicationId = Integer.parseInt(request.getParameter("id"));
        ApplicationTO to = applicationService.getApplication(applicationId);
        model.addObject("application", to);
        model.setViewName("edit");

        return model;
    }

    @RequestMapping(value = "/saveApplication", method = RequestMethod.POST)
    public ModelAndView saveContact(@ModelAttribute ApplicationTO application) {
        ModelAndView model = new ModelAndView();
        applicationService.saveApplication(application);
        model.setViewName("view");
        return model;
    }

Upvotes: 1

Views: 136

Answers (2)

ASR
ASR

Reputation: 3549

I have Missed the variable danoneValidation in the form, actually this variable present in Model class.

   <div align="center">
            <h1>New/Edit Contact</h1>
            <form:form action="saveApplication" method="post" modelAttribute="application">
            <table>
                <form:hidden path="applicationId"/>
                <tr>
                    <td>Application Name:</td>
                    <td><form:input path="applicationName" /></td>
                </tr>
                <tr>
                    <td>Start Date:</td>
                    <td><form:input path="startDate" id="startDate"/></td>
                </tr>
                <tr>
                    <td>End Date:</td>
                    <td><form:input path="endDate" id="endDate"/></td>
                </tr>
                <tr>
                    <td>Projected StartDate:</td>
                    <td><form:input path="projectedStartDate" id="projectedStartDate"/></td>
                </tr>
                <tr>
                    <td>Projected EndDate:</td>
                    <td><form:input path="projectedEndDate" id="projectedEndDate"/></td>
                </tr>
                <tr>
                    <td>Current Action:</td>
                    <td><form:input path="currentAction" /></td>
                </tr>

                <tr>
                    <td>Danone Validation:</td>
                    <td><form:input path="danoneValidation" /></td>
                </tr>

                <tr>
                    <td>Comments:</td>
                    <td><form:input path="comments" /></td>
                </tr>
                <tr>
                    <td colspan="2" align="center"><input type="submit" value="Save"></td>
                </tr>
            </table>
            </form:form>
        </div>

Upvotes: 2

OEH
OEH

Reputation: 705

Try to put a slash before the action name something like

<form:form action="/saveApplication" method="post" modelAttribute="application"> <table>

This is might be required.

Also check which is the URL that is printed on the browser bar when you submit the form. Double check that the path is what your controller is expecting.

Upvotes: -1

Related Questions