这是前端代码:
function login()
{
var userName=$("#userName").attr("value");
var password=$("#password").attr("value");
var keyword=$("#keyword").attr("value");
if(!$('#loginDto').form('validate')){
return ;
}
$("#loadInfo").html("登录中,请稍候...");
$('#loginBtn').linkbutton("disable");
//var formData = "{'userName':'"+userName+"','password':'"+password+"','keyword':'"+keyword+"'}";
var loginDto = $('#loginDto');
var userinfo = loginDto.serializeObject();
var jsonuserinfo = JSON.stringify(userinfo);
$.ajax({
type : "POST",
url : "${ctx}/page/system/checkAuth",
contentType : 'application/json',
data : jsonuserinfo,
dataType : "json",
success : function(msg){
$("#loadInfo").html("");
$('#loginBtn').linkbutton("enable");
if (msg=='OK'){
var url = $("#requestURI").attr("value");
if(url != null && url !='null' && url != ''){
document.location.href =url;
}else{
document.location.href="${ctx}/jsp/index.jsp";
}
}else{
$("#loginRslt").html(msg);
refresh();
}
}
});
}
然后这是后台代码,用的springmvc框架:
@RequestMapping(value="/system/checkAuth",method=RequestMethod.POST)
@ResponseBody
public String checkAuth(@RequestBody LoginDto dto,HttpServletRequest request)
{ }
web.xml spring配置代码:
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--SpringMVC-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>/page/*</url-pattern>
</servlet-mapping>
jquery用的版本是1.8.3
问题:请求报出415错误,到不了后台。
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 -->
</list>
</property>
</bean>
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
在springmvc-config.xml忘记配置StringHttpMessageConverter请求信息转换器!