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.
artist.java (my model class)
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;
}
}
artistcontroller.java
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 + " => " + e.getMessage();
}
} else {
return "You failed to upload " + name
+ " because the file was empty.";
}
}
}
artist.jsp
<div class="container">
<div class="row">
<c:url var="addAction" value="/artist/add"></c:url>
<form:form action="uploadProfilePic" commandName="artist" enctype="multipart/form-data">
<table class="table table-hover table-responsive table-striped" >
<c:if test="${!empty artist.artistName}">
<tr>
<td><form:label path="id">
<spring:message text="ID" />
</form:label></td>
<td><form:input path="id" readonly="true" size="8"
disabled="true" /> <form:hidden path="id" /></td>
</tr>
</c:if>
<tr>
<td><form:label path="artistName">
<spring:message text="Name" />
</form:label></td>
<td><form:input size="35" path="artistName" /> </td>
</tr>
<tr>
<td><form:label path="surname">
<spring:message text="Surname" />
</form:label></td>
<td><form:input size="35" path="surname" /></td>
</tr>
<tr>
<td><form:label path="talent">
<spring:message text="Talent" />
</form:label></td>
<td><form:input size="35" path="talent" /></td>
</tr>
<tr>
<td><form:label path="age">
<spring:message text="Age" />
</form:label></td>
<td><form:input path="age" /></td>
</tr>
<tr>
<td><form:label path="height">
<spring:message text="Height" />
</form:label></td>
<td><form:input path="height" /></td>
</tr>
<tr>
<td><form:label path="weight">
<spring:message text="Weight" />
</form:label></td>
<td><form:input path="weight" /></td>
</tr>
<tr>
<td><form:label path="hairColor">
<spring:message text="Hair Color" />
</form:label></td>
<td><form:input size="35" path="hairColor" /></td>
</tr>
<tr>
<td><form:label path="eyeColor">
<spring:message text="Eye Color" />
</form:label></td>
<td><form:input size="35" path="eyeColor" /></td>
</tr>
<tr>
<td><form:label path="ethnicity">
<spring:message text="Ethnicity" />
</form:label></td>
<td><form:input size="35" path="ethnicity" /></td>
</tr>
<tr>
<td><form:label path="photo">
<spring:message text="Photo" />
</form:label></td>
<td><form:input type="file" name="file" path="" /></td>
</tr>
<tr>
<td><form:label path="experience">
<spring:message text="Experience" />
</form:label></td>
<td><form:textarea rows="10" cols="75" path="experience" /></td>
</tr>
<tr>
<td><form:label path="twitter">
<spring:message text="Twitter Link" />
</form:label></td>
<td><form:input size="35" path="twitter" /></td>
</tr>
<tr>
<td><form:label path="facebook">
<spring:message text="Facebook Link" />
</form:label></td>
<td><form:input size="35" path="facebook" /></td>
</tr>
<tr>
<td><form:label path="instagram">
<spring:message text="Instagram Link" />
</form:label></td>
<td><form:input size="35" path="instagram" /></td>
</tr>
<tr>
<td colspan="2"><c:if test="${!empty artist.artistName}">
<input type="submit" class="btn btn-success"value="<spring:message text="Edit Artist"/>" />
</c:if> <c:if test="${empty artist.artistName}">
<input type="submit" class="btn btn-primary" value="<spring:message text="Add Artist"/>" />
</c:if></td>
<td></td>
</tr>
<tr>
<td>
<a class="btn btn-info" href="<c:url value='/artistview' />"><i class="fa fa-list-ul fa-lg"></i> View List</a>
</td>
<td></td>
</tr>
<!-- for bottom line of table -->
<tr>
<td>
</td>
<td></td>
</tr>
</table>
</form:form>
</div>
artistview.jsp
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Artist List</h2>
<h3 class="section-subheading text-muted">Lorem ipsum dolor sit amet consectetur.</h3>
</div>
</div>
<c:if test="${!empty listArtists}">
<table class="table table-hover table-responsive table-striped">
<tr>
<th>Profile Picture</th>
<th>First Name</th>
<th>Last Name</th>
<th>Talent</th>
<th>Age</th>
<th>Height</th>
<th>Weight</th>
<th>Hair Color</th>
<th>Eye Color</th>
<th>Ethnicity</th>
<th>Experience</th>
<th>Twitter Link</th>
<th>Facebook Link</th>
<th>Instagram Link</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<c:forEach items="${listArtists}" var="artist">
<tr>
<!-- <td><div style= "height: 200px; width: 200px"><img style="height: 100%; width:100%" src="photo?id=${artist.id}"/> </div>-->
<td> <img class="img-responsive" style="height: 100%; width:100%" src="/img/artistphotos/${artist.photo}" alt="" /> </td>
<td>${artist.artistName}</td>
<td>${artist.surname}</td>
<td>${artist.talent}</td>
<td>${artist.age}</td>
<td>${artist.height}</td>
<td>${artist.weight}</td>
<td>${artist.hairColor}</td>
<td>${artist.eyeColor}</td>
<td>${artist.ethnicity}</td>
<td>${artist.experience}</td>
<td>${artist.twitter}</td>
<td>${artist.facebook}</td>
<td>${artist.instagram}</td>
<td><a class="btn btn-success" href="<c:url value='/edit/${artist.id}' />"><i class="fa fa-pencil fa-lg"></i> Edit</a></td>
<td><a class="btn btn-danger" href="<c:url value='/remove/${artist.id}' />"><i class="fa fa-trash-o fa-lg"></i> Delete</a></td>
</tr>
</c:forEach>
</table>
</c:if>
there is no error showing in the console of eclipse, but here is the error im receiving from the browser:
HTTP Status 400 -
type Status report
message
description The request sent by the client was syntactically incorrect.
Apache Tomcat/8.0.21
also the url on top displays this:
http://localhost:8080/artistweb/edit/uploadProfilePic