简体   繁体   中英

Neither BindingResult nor plain target object for bean name 'parametre'

I'm working with spring MVC, so Basically im creating a forum wich will take a file and radioButton as Input: form_li.jsp:

<f:form  id="form1"
         name="form1"
         modelAttribute="parametre"
         action="${addTreat}"
         method="POST"
         enctype="multipart/form-data">

    <table>
        <tr>
            <td>xslx File : </td>
            <td>
                <f:input id="filepd" path="fileCom" name="filepd"  type="file" />
            </td>
        </tr>

        <tr>
            <td>Choice </td>
            <td>
                <div>
                    <f:input id="az" name="az" path="choice" type="radio" value="false" />
                    <label for="az">1</label>
                    <f:input id="aj" name="aj"  path="choice" type="radio" value="true"/>
                    <label for="aj">2</label>
                </div>
            </td>
        </tr>

        <tr>
            <div align="center">
                <f:input type="submit" value="Validate" path="" />
            </div>
        </tr>
    </table>
</f:form>

for myController :

@RequestMapping(value="/addTreat", method= RequestMethod.POST)
public String addTr(HttpServletRequest req,
        BindingResult result,
        ModelMap model,
        @RequestParam("parametre") Parametre parametre) {

    model.addAttribute("parametre", new Parametre());
    return form_li;
}

for the class Parametre.java:

public class Parametre {

    private String choice;
    private MultipartFile fileCom;
    //getters and setters
    //default constructor
}

my problem is when running the application and going to the /addTreat url. im getting the famous Neither BindingResult nor plain target object for bean name 'parametre' available as request attribute. i have tried multiple solutions but i doesn't work. please can anyone help to fix this problem.

So many things are messed up here, I recommend you to read some modelAttribute examples, there are dozens, even on the official spring documentation. It looks like you confuse model object with simple request param, for the second one you don't even need BindingResult . Also the syntax of your form action is incorrect.

action="${addTreat}" change to action="/addTreat"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM