我試圖發送一個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