jquery ajax 报交请求返回 HTTP 400 错误
2016-03-24 10:49
381 查看
提交请求的AJAX代码如下:
点击(此处)折叠或打开
$.ajax({
url: "${ctx}/selfhelp/userAttributeAnalysis/userAttributeList",
type: "POST",
data:{appId:appId,
type:type,
startDate:startDate,
endDate:endDate,
deviceType:deviceType,
displayType:displayType},
dataType: "json",
success: paddinglist
});
里面data是传的一些参数。
ACTION使用的是SpringMVC的注解方式,接收方法如下:
点击(此处)折叠或打开
@RequestMapping(value = "/userAttributeList")
@ResponseBody
public List<UserAttribute> userAttributeList(HttpServletRequest request,
int type, String appId, int deviceType, int displayType,
Date startDate, Date endDate, ModelMap modelMap) throws Exception {
。。。。。。。。
}
接收的地方也接收了这些参数,但通过DEBUG看,根本就没到这个方法里,在外层就抛错了。
于是我Debug在DispatcherServlet上,发现在框架自动填充Date类型时,使用的格式是"yyyy-MM-dd HH:mm:ss",是在父类里有以下代码:
点击(此处)折叠或打开
@InitBinder
public void initBinder(ServletRequestDataBinder binder)
{
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
但我在WEB上设置的日期,格式是yyyy-MM-dd。
原来如此,那解决办法就显而易见了。可以在ajax里将时间传入时加入时分秒,也可以改initBinder。
点击(此处)折叠或打开
$.ajax({
url: "${ctx}/selfhelp/userAttributeAnalysis/userAttributeList",
type: "POST",
data:{appId:appId,
type:type,
startDate:startDate,
endDate:endDate,
deviceType:deviceType,
displayType:displayType},
dataType: "json",
success: paddinglist
});
里面data是传的一些参数。
ACTION使用的是SpringMVC的注解方式,接收方法如下:
点击(此处)折叠或打开
@RequestMapping(value = "/userAttributeList")
@ResponseBody
public List<UserAttribute> userAttributeList(HttpServletRequest request,
int type, String appId, int deviceType, int displayType,
Date startDate, Date endDate, ModelMap modelMap) throws Exception {
。。。。。。。。
}
接收的地方也接收了这些参数,但通过DEBUG看,根本就没到这个方法里,在外层就抛错了。
于是我Debug在DispatcherServlet上,发现在框架自动填充Date类型时,使用的格式是"yyyy-MM-dd HH:mm:ss",是在父类里有以下代码:
点击(此处)折叠或打开
@InitBinder
public void initBinder(ServletRequestDataBinder binder)
{
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
但我在WEB上设置的日期,格式是yyyy-MM-dd。
原来如此,那解决办法就显而易见了。可以在ajax里将时间传入时加入时分秒,也可以改initBinder。
相关文章推荐
- commons-httpclient-3.1.jar的一些用处
- 神经网络那些事儿(一)
- httpmine jar包
- 数据仓库专题22-网络用户行为数据采集标准规范设计
- [IOS 开发] iOS音频篇:使用AVPlayer播放网络音乐
- 网络地址转换NAT原理及应用
- iOS9 HTTP 不能正常使用的解决办法
- Linux网络属性配置
- Meta http-equiv属性
- Android 6.0 使用 Apache HttpClient
- 三次握手和四次挥手
- http方式调用webservice
- 使用Service和BroadcastReceiver实时监听网络状态
- 用httpPost对JSON发送和接收的例子
- Android网络图片加载内存溢出(OOM)解决方案
- HTTP传输byte[ ] 两种方式
- iOS音频篇:使用AVPlayer播放网络音乐
- C++ 用libcurl库进行http通讯网络编程
- 异构信息网络--基本概念和定义学习笔记
- 深度学习(三十四)对抗自编码网络-未完待续