Hello All,

I would like to upload a file using spring 2.5, however I'm getting a nullpointer exception for the file object.

I have put the multipartResolver in the xml File. If you can spot a mistake, can you please let me know. Maybe I'm missing something or I'm not doing something correctly. I tried using the @RequestParam too instead of the ModelAttribute, that didn't help much either. I'm still getting the nullpointer exception.

I have done this in my controller
Code:
    @RequestMapping(method = RequestMethod.POST)
    public ModelAndView saveStudentListFile(ModelMap model, @ModelAttribute FileUploadBean fileUploadBean) {
        
        System.out.println("The name of the file is: " + fileUploadBean.getFilename());
        System.out.println("Size of file is: " + fileUploadBean.getFiledata().isEmpty());
    ...
My FileUploadBean class looks like this:

Code:
public class FileUploadBean {
    private String filename;
    private MultipartFile filedata;

    // getter and setter methods
...
My jsp file looks like this:
Code:
<form:form modelAttribute="FileUploadBean" method="post" action="uploadfile.htm" enctype="multipart/form-data">
                        <div id="uploadField">
                            <label for="filename" >Name: </label>
                            <form:input path="filename" />
                        </div>
                        <div id="uploadField">
                            <label for="filedata">File: </label>
                            <input type="file" name="filedata" /><br/>
                        </div>
                        <div id="uploadField">
                            <label for="submit">&nbsp;</label>
                            <input type="submit"/>
                        </div>
                    </form:form>

Thanks,
Nguni