我试图发送一个Ajax请求,Spring MVC的控制器,并将其映射到相应的Java类:春3.0 MVC阿贾克斯例如
public class Person implements Serializable {
private MutableLong Id = new MutableLong();
@NotEmpty
@Size(min = 1, max = 50)
String FirstName=null;
@NotEmpty
@Size(min = 1, max = 50)
String LastName=null;
public Person(){}
public long getId(){
return this.Id.longValue();
}
//getters and setters
}
那么我的JavaScript,它发送AJAX请求:
function loadXMLDoc(){
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open("POST","/authenticate.dlp", true);
xmlHttp.setRequestHeader('Content-Type', 'application/json');
param = '{\"FirstName\"=\"test\",\"LastName\"=\"test2\"}';
xmlHttp.send(param);
}
,然后控制器本身:
@RequestMapping(value="/authenticate.dlp",method = RequestMethod.POST)
@ResponseBody
public String getAjax(@RequestBody Person person){
Set<ConstraintViolation<Person>> failures = validator.validate(person);
if(!failures.isEmpty())
//......
}
它看起来像没有来自服务器的响应。如果我使用招,我看到来自服务器的以下消息:
,因为请求的实体是不被请求方式请求 资源支持的格式 服务器拒绝这个请求 () 。
我在做什么错?
我们需要看看您的spring appcontext的内容 – skaffman 2010-10-18 10:54:43