Announcement Announcement Module
No announcement yet.
Attempting to allow user to upload a file, but getting Null Pointer Exception Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Attempting to allow user to upload a file, but getting Null Pointer Exception

    Hey all,

    I've posted the full question on at the following link. Since the need for a solution is urgent, I decided that I should post it on this forum as well. Thanks for taking the time to look.

    Regardless, this is my setup...


    public class UploadForm {
    private CommonsMultipartFile fileData;
    public CommonsMultipartFile getFileData() {
        System.out.println("REACHED GET METHOD");
        return fileData;
    public void setFileData(CommonsMultipartFile fileData) {
        System.out.println("REACHED SET METHOD");
        this.fileData = fileData;

    <%@ taglib uri="" prefix="c" %>
    <%@ taglib uri="" prefix="form" %>
    <%@ page session="false" %>
    <title>Upload Document</title>
        <script type="text/javascript" src=""></script>
        <script type="text/javascript">     
        <script type="text/javascript" src="resources/rulesextractor.js"></script>
        <link rel="stylesheet" type="text/css" href="./resources/css/rulesextractor.css" />     
    <c:import url = "./header.jsp">
        <c:param name = "title" value = "Upload Document"/>
        <c:param name = "region" value = "${region}"/>
        Please choose a Document to upload
    <form:form method="POST" modelAttribute="uploadForm" commandName="uploadForm" name="uploadForm" id="uploadForm" enctype="multipart/form-data">
        <form:input path="fileData" name="fileData" type="file"/>
        <input type="submit" name="submit" value="Submit" id="subbtn"/>
        <input type="button" value="Main Menu" onclick="back();"/>

    public class UploadController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(FlowController.class);
    //private UserPreferences userPreferences;  
    GenericSearchBO genericSearchBO;
    @RequestMapping(value = "upload", method = RequestMethod.GET)
    public String getUploadPage(Model m){"UploadController: Getting Upload page");
        m.addAttribute(new UploadForm());
        return "/pages/upload";
    @RequestMapping(method = RequestMethod.POST)
    public String create(@Valid UploadForm UploadForm, BindingResult result){
        if (result.hasErrors())
          for(ObjectError error : result.getAllErrors())
            System.err.println("Error: " + error.getCode() +  " - " + error.getDefaultMessage());
          return "/pages/upload";
        // Some type of file processing...
        System.err.println("Test upload: " + UploadForm.getFileData());
        return "redirect:/pages/upload";
    The issue here is that I am in fact entering the Controller's public String create(@Valid UploadForm UploadForm, BindingResult result) method, but UploadForm is being passed as a null value and I can't, for the life of me, figure it out and it's getting quite frustrating. I do not believe that the file that the user is uploading is being passed to the model using the set method. THe reason I belive this is because the get method's
    System.out.println("REACHED GET METHOD");
    is being reached, but the model's set method's
    System.out.println("REACHED SET METHOD");
    is not.
    Last edited by sukmul; Mar 7th, 2013, 12:15 PM. Reason: model, view, controller

  • #2
    This issue has yet to be resolved, so any suggestions will be greatly appreciated!