HTTP 406错误发生升级到Spring MVC的4.1使用JSON
问题描述:
升级到Spring MVC的4.1.1后,当我使用JSON,它会出现HTTP 406错误。HTTP 406错误发生升级到Spring MVC的4.1使用JSON
的pom.xml
<!-- JSON Support -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
Controller.java
@RequestMapping(value = "/login.action", method = RequestMethod.POST)
public @ResponseBody HashMap<String, Boolean> loginAction(
@RequestParam(value="username", required=true) String username,
@RequestParam(value="password", required=true) String password,
HttpServletRequest request,
HttpSession session,
Model model) {
String ipAddress = request.getRemoteAddr();
HashMap<String, Boolean> result = getLoginResult(username, password);
logger.info(String.format("User: [Username=%s] tried to log in at %s", new Object[] {username, ipAddress}));
if (result.get("isSuccessful")) {
getSession(request, session, this.user);
}
return result;
}
的login.jsp
<script type="text/javascript">
function doLoginAction(username, password) {
var postData = 'username=' + username + '&password=' + password;
$.ajax({
type: 'POST',
url: '<c:url value="/accounts/login.action" />',
data: postData,
dataType: 'JSON',
success: function(result){
console.log(result);
return processLoginResult(result);
}
});
}
</script>
日志消息将出正常放置在控制台上。 而且代码在Spring MVC 4.0.5中正常工作。
你知道如何解决它吗?非常感谢。
答
升级杰克逊的版本应该可以解决这个问题。
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.3</version>
</dependency>
你的意思是除去* org.codehaus.jackson *依赖,并添加* com.fasterxml.jackson.core *?这不适用于我的机器。它抛出模型类没有发现异常。 – 2014-10-20 09:33:20
我仍然认为,第一步要解决这个问题正在更新的依赖。您可能需要在应用程序中更新导入语句。否则,你可以更新你的问题,并在那里添加一个完整的堆栈跟踪。 – 2014-10-20 11:40:46