我正在尝试发送json数据并获取json数据。我在<annotation-driven />
中配置了servlet-context.xml
,我正在使用Spring框架版3.1.0.RELEASE
。当我发送请求时,浏览器告诉我它对从服务器返回的数据不满意并给出了406错误。当我看到服务器的响应时,我看到tomcat 6服务器返回的整个406页面。
我在杰克逊/杰克逊处理器的pom中得到了关注:
<!-- Jackson -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-xc</artifactId>
<version>1.9.4</version>
</dependency>
<!-- Jackson JSON Processor -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.8.1</version>
</dependency>
以下是我用来发送json请求的jquery代码:
$(function(){$(".sutmit-button").click(function(){
var dataString=$("#app-form").serialize();
$.ajax({
type:"POST",
url:"apply.json",
data:dataString,
success:function(data, textStatus, jqXHR){
console.log(jqXHR.status);
console.log(data);
$('.postcontent').html("<div id='message'></div>");
$('#message').html("<h3>Request Submitted</h3>").append("<p>Thank you for submiting your request.</p>").hide().fadeIn(1500,function(){$('#message');});
},
error:function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR.status);
$('.postcontent').html("<div id='message'></div>");
$('#message').html("<h3>Request failed.</h3>").hide().fadeIn(1500,function(){$('#message');});
},
dataType: "json"
});
return false;});});
以下是处理请求的Controller:
@RequestMapping(method = RequestMethod.POST, value="apply", headers="Accept=application/json")
public @ResponseBody Application processFranchiseeApplicationForm(HttpServletRequest request) {
//...
Application application = new Application(...);
//...
logger.debug(application);
return application;
}
我无法弄清楚我可能会收到此错误的原因。有人可以帮我理解为什么我会收到给定的错误吗?
感谢。