title: Request Sent by the Client was syntactically incorrect with spring mvc - hunch is on photo upload method
body: <p>im doing a web and upon testing it i encountered this , Request Sent by the Client was syntactically incorrect. i dont know which is the one giving the error, but to say, i have a model class that is artist.java. My jsp pages are artist,jsp and artistview.jsp. and it is being controlled by the artistcontroller.java. I am getting this error when i edit a an artist from my artistview.jsp. it is then directed to the edit portion of artist.jsp. after editing the details filling all details again, and i press edit artist, i get the error. i have a hunch that it is coming from the uploadprofilepic method, but cant figure it out. hope you could help me on this. thanks in advance. 
  here are my codes. </p>
  
  <p>artist.java (my model class)</p>
  
  <pre><code>package com.artistlabprod.model;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Lob;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="ARTIST")
  public class Artist {
  
  @Id
  @Column(name="ID")
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  private int id;
  
  @Column(name="ARTISTNAME") 
  private String artistName;
  
  @Column(name="SURNAME") 
  private String surname;
  
  @Column(name="TALENT") 
  private String talent;
  
  @Column(name="AGE")
  private int age;
  
  @Column(name="HEIGHT")
  private String height;
  
  @Column(name="WEIGHT")
  private String weight;
  
  @Column(name="HAIRCOLOR") 
  private String hairColor;
  
  @Column(name="EYECOLOR") 
  private String eyeColor;
  
  @Column(name="ETHNICITY") 
  private String ethnicity;
  
  @Column(name="EXPERIENCE") 
  private String experience;
  
  @Column(name="PHOTO")
  private String photo;
  
  @Column(name="TWITTER") 
  private String twitter;
  
  @Column(name="FACEBOOK") 
  private String facebook;
  
  @Column(name="INSTAGRAM") 
  private String instagram;
  
  
  
  public Artist() {
  }
  
  
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  public String getArtistName() {
      return artistName;
  }
  
  
  public void setArtistName(String artistName) {
      this.artistName = artistName;
  }
  
  
  
  public String getSurname() {
      return surname;
  }
  
  
  public void setSurname(String surname) {
      this.surname = surname;
  }
  
  
  public String getTalent() {
      return talent;
  }
  
  
  public void setTalent(String talent) {
      this.talent = talent;
  }
  
  
  public int getAge() {
      return age;
  }
  
  public void setAge(int age) {
      this.age = age;
  }
  
  public String getHeight() {
      return height;
  }
  
  public void setHeight(String height) {
      this.height = height;
  }
  
  public String getWeight() {
      return weight;
  }
  
  public void setWeight(String weight) {
      this.weight = weight;
  }
  
  public String getHairColor() {
      return hairColor;
  }
  
  public void setHairColor(String hairColor) {
      this.hairColor = hairColor;
  }
  
  public String getEyeColor() {
      return eyeColor;
  }
  
  public void setEyeColor(String eyeColor) {
      this.eyeColor = eyeColor;
  }
  
  public String getEthnicity() {
      return ethnicity;
  }
  
  public void setEthnicity(String ethnicity) {
      this.ethnicity = ethnicity;
  }
  
  public String getExperience() {
      return experience;
  }
  
  public void setExperience(String experience) {
      this.experience = experience;
  }
  
  public String getPhoto() {
      return photo;
  }   
  
  public void setPhoto(String photo) {
      this.photo = photo;
  }
  
  
  public String getTwitter() {
      return twitter;
  }
  
  
  public void setTwitter(String twitter) {
      this.twitter = twitter;
  }
  
  
  public String getFacebook() {
      return facebook;
  }
  
  
  public void setFacebook(String facebook) {
      this.facebook = facebook;
  }
  
  
  public String getInstagram() {
      return instagram;
  }
  
  
  public void setInstagram(String instagram) {
      this.instagram = instagram;
  }
  }
  </code></pre>
  
  <p>artistcontroller.java</p>
  
  <pre><code>package com.artistlabprod.controller;
  
  import java.io.BufferedOutputStream;
  import java.io.ByteArrayInputStream;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import javax.servlet.ServletContext;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.validation.Valid;
  import org.apache.commons.io.FileUtils;
  import org.apache.commons.io.IOUtils;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.http.MediaType;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.ResponseBody;
  import org.springframework.web.context.ServletContextAware;
  import org.springframework.web.multipart.MultipartFile;
  import org.springframework.web.servlet.ModelAndView;
  
  import com.artistlabprod.model.Artist;
  import com.artistlabprod.service.ArtistService;
  
  @Controller
  public class ArtistController  {
  
  private ArtistService artistService;
  
  
  
  
  public ArtistService getArtistService() {
      return artistService;
  }  
  
  @Autowired(required=true)
  @Qualifier(value="artistService")
  public void setArtistService(ArtistService ps){
      this.artistService = ps;
  }
  
  @RequestMapping("/")
  public String home(Model model) {
      model.addAttribute("listArtists", this.artistService.listArtists());
      return "home";
  
  }
  
  
   @RequestMapping(value = "/index", method = RequestMethod.GET)
   public ModelAndView getHome() {
       ModelAndView modelandview = new ModelAndView ("index");
       return modelandview;
   }
  
  
  
   @RequestMapping(value = "/aboutus", method = RequestMethod.GET)
   public ModelAndView getAboutus() {
       ModelAndView modelandview = new ModelAndView ("aboutus");
       return modelandview;
   }
  
   @RequestMapping(value = "/contactus", method = RequestMethod.GET)
   public ModelAndView getContactus() {
       ModelAndView modelandview = new ModelAndView ("contactus");
       return modelandview;
   }
  
  
  
  @RequestMapping(value = "/artists", method = RequestMethod.GET)
  public String listArtists(Model model) {
      model.addAttribute("artist", new Artist());
      model.addAttribute("listArtists", this.artistService.listArtists());
      return "artist";
  }
  
  
  @RequestMapping(value = "/artistview", method = RequestMethod.GET)
  public String listofArtists(Model model) {
      model.addAttribute("listArtists", this.artistService.listArtists());
      return "artistview";
  }
  
  
  @RequestMapping(value= "/artist/add", method = RequestMethod.POST)
  public String addArtist(){ 
      return "redirect:/artistview";
  }
  
  
  @RequestMapping("/remove/{id}")
  public String removeArtist(@PathVariable("id") int id){
      this.artistService.removeArtist(id);
      return "redirect:/artists";
  }
  
  @RequestMapping("/edit/{id}")
  public String editArtist(@PathVariable("id") int id, Model model) {
      model.addAttribute("artist", this.artistService.getArtistById(id));     
      model.addAttribute("listArtists", this.artistService.listArtists());
      return "artist";
  }
  
  
  @RequestMapping(value = "/uploadProfilePic", method = RequestMethod.POST)
  public String uploadBackground(@ModelAttribute("artist") Artist p, @RequestParam("file") MultipartFile file, Model model) {
      String name="";
      if(p.getId() == 0){
          //add a new inventory item
          this.artistService.addArtist(p);
          p.setPhoto("photo-"+ p.getId() + ".jpg");
          this.artistService.updateArtist(p);
          name = p.getPhoto();
      }else{
          //update an existing inventory item
          this.artistService.updateArtist(p);
      } 
  
  
      if (!file.isEmpty()) {
          try {
              byte[] bytes = file.getBytes();
  
              // Creating the directory to store file
              String rootPath = "C:" + File.separator + "Users"
                      + File.separator + "User Folder"                        
                      + File.separator + "Documents" 
                      + File.separator + "appdevupitdc" 
                      + File.separator + "workspace" 
                      + File.separator + ".metadata"
                      + File.separator + ".plugins" 
                      + File.separator + "org.eclipse.wst.server.core" 
                      + File.separator + "tmp1" 
                      + File.separator + "webapps" 
                      + File.separator + "img"
                      + File.separator + "artistphotos";
  
  
              File dir = new File(rootPath);
              if (!dir.exists())
                  dir.mkdirs();
  
              // Create the file on server
              File serverFile = new File(dir.getAbsolutePath()
                      + File.separator + name);
              BufferedOutputStream stream = new BufferedOutputStream(
                      new FileOutputStream(serverFile));
              stream.write(bytes);
              stream.close();                 
  
              //return listofArtists(model);
              return addArtist();
          } catch (Exception e) {
              return "You failed to upload " + name + " =&gt; " + e.getMessage();
          }
      } else {
              return "You failed to upload " + name
                  + " because the file was empty.";
      }
  }
  
  }
  </code></pre>
  
  <p>artist.jsp</p>
  
  <pre><code>&lt;div class="container"&gt;
   &lt;div class="row"&gt;  
  &lt;c:url var="addAction" value="/artist/add"&gt;&lt;/c:url&gt;
  &lt;form:form action="uploadProfilePic" commandName="artist" enctype="multipart/form-data"&gt;
      &lt;table class="table table-hover table-responsive table-striped" &gt;
          &lt;c:if test="${!empty artist.artistName}"&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;form:label path="id"&gt;
                          &lt;spring:message text="ID" /&gt;
                      &lt;/form:label&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;form:input path="id" readonly="true" size="8"
                          disabled="true" /&gt; &lt;form:hidden path="id" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/c:if&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="artistName"&gt;
                      &lt;spring:message text="Name" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input size="35" path="artistName" /&gt; &lt;/td&gt;
  
  
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="surname"&gt;
                      &lt;spring:message text="Surname" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input size="35" path="surname" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="talent"&gt;
                      &lt;spring:message text="Talent" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input size="35" path="talent" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="age"&gt;
                      &lt;spring:message text="Age" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="age" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="height"&gt;
                      &lt;spring:message text="Height" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="height" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="weight"&gt;
                      &lt;spring:message text="Weight" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="weight" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="hairColor"&gt;
                      &lt;spring:message text="Hair Color" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input  size="35" path="hairColor" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="eyeColor"&gt;
                      &lt;spring:message text="Eye Color" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input  size="35" path="eyeColor" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="ethnicity"&gt;
                      &lt;spring:message text="Ethnicity" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input  size="35" path="ethnicity" /&gt;&lt;/td&gt;
          &lt;/tr&gt;           
  
  
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="photo"&gt;
                      &lt;spring:message text="Photo" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input type="file" name="file" path="" /&gt;&lt;/td&gt;
          &lt;/tr&gt;                   
  
  
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="experience"&gt;
                      &lt;spring:message text="Experience" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:textarea rows="10" cols="75" path="experience" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="twitter"&gt;
                      &lt;spring:message text="Twitter Link" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input size="35" path="twitter" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="facebook"&gt;
                      &lt;spring:message text="Facebook Link" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input size="35" path="facebook" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="instagram"&gt;
                      &lt;spring:message text="Instagram Link" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input size="35" path="instagram" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
  
  
          &lt;tr&gt;
              &lt;td colspan="2"&gt;&lt;c:if test="${!empty artist.artistName}"&gt;
                      &lt;input type="submit" class="btn btn-success"value="&lt;spring:message text="Edit Artist"/&gt;" /&gt;
                  &lt;/c:if&gt; &lt;c:if test="${empty artist.artistName}"&gt;
                      &lt;input type="submit" class="btn btn-primary" value="&lt;spring:message text="Add Artist"/&gt;" /&gt;
                  &lt;/c:if&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td&gt;
          &lt;a class="btn btn-info" href="&lt;c:url value='/artistview' /&gt;"&gt;&lt;i class="fa fa-list-ul fa-lg"&gt;&lt;/i&gt; View List&lt;/a&gt;
          &lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;!-- for bottom line of table --&gt;
          &lt;tr&gt;
          &lt;td&gt;
          &lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
  
  
      &lt;/table&gt;
  &lt;/form:form&gt;
  
  
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>artistview.jsp</p>
  
  <p></p>
  
  <pre><code>    &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-lg-12 text-center"&gt;
                  &lt;h2 class="section-heading"&gt;Artist List&lt;/h2&gt;
                  &lt;h3 class="section-subheading text-muted"&gt;Lorem ipsum dolor sit amet consectetur.&lt;/h3&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
  
  
  &lt;c:if test="${!empty listArtists}"&gt;
      &lt;table class="table table-hover table-responsive table-striped"&gt;
          &lt;tr&gt;
              &lt;th&gt;Profile Picture&lt;/th&gt;                
              &lt;th&gt;First Name&lt;/th&gt;
              &lt;th&gt;Last Name&lt;/th&gt;
              &lt;th&gt;Talent&lt;/th&gt;
              &lt;th&gt;Age&lt;/th&gt;
              &lt;th&gt;Height&lt;/th&gt;
              &lt;th&gt;Weight&lt;/th&gt;
              &lt;th&gt;Hair Color&lt;/th&gt;
              &lt;th&gt;Eye Color&lt;/th&gt;
              &lt;th&gt;Ethnicity&lt;/th&gt;
              &lt;th&gt;Experience&lt;/th&gt;
              &lt;th&gt;Twitter Link&lt;/th&gt;
              &lt;th&gt;Facebook Link&lt;/th&gt;
              &lt;th&gt;Instagram Link&lt;/th&gt;
              &lt;th&gt;Edit&lt;/th&gt;
              &lt;th&gt;Delete&lt;/th&gt;
          &lt;/tr&gt;
          &lt;c:forEach items="${listArtists}" var="artist"&gt;
              &lt;tr&gt;
               &lt;!--  &lt;td&gt;&lt;div style= "height: 200px; width: 200px"&gt;&lt;img style="height: 100%; width:100%" src="photo?id=${artist.id}"/&gt; &lt;/div&gt;--&gt;
               &lt;td&gt; &lt;img class="img-responsive" style="height: 100%; width:100%" src="/img/artistphotos/${artist.photo}" alt="" /&gt; &lt;/td&gt;
                  &lt;td&gt;${artist.artistName}&lt;/td&gt;
                  &lt;td&gt;${artist.surname}&lt;/td&gt;
                  &lt;td&gt;${artist.talent}&lt;/td&gt;
                  &lt;td&gt;${artist.age}&lt;/td&gt;
                  &lt;td&gt;${artist.height}&lt;/td&gt;
                  &lt;td&gt;${artist.weight}&lt;/td&gt;
                  &lt;td&gt;${artist.hairColor}&lt;/td&gt;
                  &lt;td&gt;${artist.eyeColor}&lt;/td&gt;
                  &lt;td&gt;${artist.ethnicity}&lt;/td&gt;
                  &lt;td&gt;${artist.experience}&lt;/td&gt;
                  &lt;td&gt;${artist.twitter}&lt;/td&gt;
                  &lt;td&gt;${artist.facebook}&lt;/td&gt;
                  &lt;td&gt;${artist.instagram}&lt;/td&gt;
                  &lt;td&gt;&lt;a class="btn btn-success" href="&lt;c:url value='/edit/${artist.id}' /&gt;"&gt;&lt;i class="fa fa-pencil fa-lg"&gt;&lt;/i&gt; Edit&lt;/a&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;a class="btn btn-danger" href="&lt;c:url value='/remove/${artist.id}' /&gt;"&gt;&lt;i class="fa fa-trash-o fa-lg"&gt;&lt;/i&gt; Delete&lt;/a&gt;&lt;/td&gt;
  
  
              &lt;/tr&gt;
          &lt;/c:forEach&gt;
      &lt;/table&gt;
  &lt;/c:if&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>there is no error showing in the console of eclipse, but
  here is the error im receiving from the browser:</p>
  
  <pre><code>HTTP Status 400 -
  
  type Status report
  
  message
  
  description The request sent by the client was syntactically incorrect.
  Apache Tomcat/8.0.21
  </code></pre>
  
  <p>also the url on top displays this:</p>
  
  <pre><code>http://localhost:8080/artistweb/edit/uploadProfilePic
  </code></pre>