I am newbie to Spring MVC. I was stuck by an error while running my project Error-The request sent by the client was syntactically incorrect. I have an enti
In my case, I try to create an object that has ID and NAME as attributes. ID is int, NAME is String. But my js set values like this ID = '', NAME = 'brabrabra...'
After set ID = 0, problem is fixed.
I had a similar issue recently and solved it by annotating my Date field with the @DateTimeFormat
. In your case, you would edit your PatientInfo.java
file to:
import org.spring.framework.annotation.DateTimeFormat;
@Column(name = "DateOfBirth")
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern = ${pattern})
private Date dateOfBirth;
Make sure to replace ${pattern}
with a string representing the format that will be received (e.g. "yyyy-MM-dd").
I think the issue is that Spring doesn't know how to deserialize the date your browser client sends when submitting the following input
field in
<tr name="tstest">
<td>Date Of Birth</td>
<td><form:input path="dateOfBirth" name="timestamp" value=""/>
<a href="javascript:show_calendar('document.tstest.timestamp', document.tstest.timestamp.value);"><img src="../images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the timestamp"></a>
</td>
</tr>
Spring doesn't know how to take the value that you enter into that field and convert it into a Date
object. You need to register a PropertyEditor
for that. For example, add the following to your @Controller
class
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
sdf.setLenient(true);
binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
}
Obviously, change the SimpleDateFormat
to whatever your client is sending.
On a related note, you're sending a 302 response by sending a redirect
return "redirect:/full-reg";
Remember that request and model attributes only live for the duration of one request. So when your client send the request to full-reg
, none of the form input parameters you sent originally exist any more. You should re-think how you do this.
I came across the same error this morning. The problem with my code was that I had declared a variable as an integer in my form binding object but on the actual form I was capturing text. Changing the variable to the correct type worked out for me
This happens when the defined binding does not match to what the user is sending. The most common issues are:
So, in general, be sure that:
@PathVariable(value="myVariableName", String myVariable)
where the path defines @RequestMapping(value = "/userInfo/myVariableName", method = RequestMethod.GET)
try with this (with /add-update2
instead of just add-update2
) and replace modelAttribute
by commandName
<form:form commandName="patientInfo" method="POST" action="/add-update2">