Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1073167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:57:21+00:00 2026-05-16T20:57:21+00:00

I am working on a Spring web application and need to implement a simple

  • 0

I am working on a Spring web application and need to implement a simple FileUpload for one of my pages.

The page for the JSP contains the following snippet of code which included an upload field for uploading the file.

<form:form commandName="editMemberInfoModelObj" method="post" enctype="multipart/form-data">
        <h1>Edit Member Information</h1>
        <table>
            //Other Form Input Fields ...
            <tr>
                <td>File</td>
                <td><input type="file" name="file"/></td>
            </tr>
            <tr>
                <td><input type="submit" value="Update Info"/></td>
            </tr>
        </table>
    </form:form>

The model for this JSP looks like the following

public class EditMerchandiserModel(){
        private MultipartFile file;

        //getters and setters for all the properties
}

The code in the controller that handles the file upload looks like the following

    if(model.getFile().isEmpty())  -->THROWING NULLPOINTER EXCEPTION HERE
    {
        MultipartFile file = model.getFile();
        String fileName = file.getOriginalFilename();
        String filePath = "/usr/local/" + fileName;
        FileOutputStream fos = new FileOutputStream(filePath);
         try 
             {

            fos.write(file.getBytes());
         } catch (IllegalStateException e) {
            System.out.println(e);

         }
         finally{
             fos.close();
         }
    }

I am unable to hit the inside code because it is reading in the file as a null value.
Why is it not binding the value to the field?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:57:21+00:00Added an answer on May 16, 2026 at 8:57 pm

    It looks like your file input box has the name “file” while the property it’s supposed to bind to has the name “photo” (at least you’re trying to retrieve it using “getPhoto()”. Spring is smart, but it ain’t that smart. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have working web-application with applicationContext.xml in WEB-INF/config/applicationContext.xml. Now i need to implement some
I am working on a Spring web application where I have a need to
i am working on a spring 3 web service application and on it i
I'm working on a Java web application (Adobe Flex front-end, JPA/Hibernate/BlazeDS/Spring MVC backend) and
When working with web-designers in a Spring-MVC and JSP environment, are there any tools
I am working on Spring-Hibernate-Websphere application and sybase as database. Following is the code
I need to load the i18n localization properties of my Spring web application as
I'm working on a web application using Spring 3.0 and hibernate 3 with SQL
I am working on asp.net web application in which i need to show the
I am working on a web application which is based on spring MVC. We

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.