SpringMVC错误,商品添加信息HTTP Status 400 – Bad Request
记录一个自己在做商品信息显示与传递数据的时候出现的错误,
HTTP Status 400 – Bad Request
Type Status Report
Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
简单的说我在商品信息里有个Date createDate的属性类型。但是在前台传数据的时候是个String类型,因此会出现这个错误,可能是这个错误吧,我当时没复制,找了个网上问题相似的。我最开始解决这问题是在
SpringMVC.xml里配置了
<bean id="conversionServer"
class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<!-- 日期转换器 -->
<property name="converters">
<list>
<bean class="com.mju.band3.Converter.DateConverter" />
</list>
</property>
</bean>
这个是DateConverter代码
package com.mju.band3.Converter; import org.springframework.core.convert.converter.Converter; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date; public class DateConverter implements Converter<String, Date> {
private String datePattern="yyyy-MM-dd";
@Override
public Date convert(String s) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern); try {
return simpleDateFormat.parse(s);
} catch (ParseException e) {
throw new IllegalArgumentException("无效的日期格式");
} }
} 然而他出现了一个我弄了好几天都没弄好的问题,也就是我的JSP所有样式失效,而且也蹦掉,怀疑是jar版本问题,因为我再练习这个项目的时候出现了N多个版本问题的错误,
反正我是不知道为啥,那位大神能指点迷津, 那么我就去换了个方法,觉得这个方法也不错。贴上我的Bean
package com.mju.band3.Bean; import java.text.SimpleDateFormat;
import java.util.Date; public class Item {
private Integer id;
private String name;
private float price;
private String detail;
private String pic;
private Date createtime; public Item(Integer id, String name, float price, String detail, String pic, Date createtime) {
this.id = id;
this.name = name;
this.price = price;
this.detail = detail;
this.pic = pic;
this.createtime = createtime;
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public float getPrice() {
return price;
} public void setPrice(float price) {
this.price = price;
} public String getDetail() {
return detail;
} public void setDetail(String detail) {
this.detail = detail;
} public String getPic() {
return pic;
} public void setPic(String pic) {
this.pic = pic;
} public Date getCreatetime() {
return createtime;
} public void setCreatetime(String str) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date createtime;
try {
createtime = sdf.parse(str);
this.createtime = createtime;
} catch (Exception e) {
e.printStackTrace();
}
} public Item() {
super();
} @Override
public String toString() {
return "Item{" +
"id=" + id +
", name='" + name + '\'' +
", price=" + price +
", detail='" + detail + '\'' +
", pic='" + pic + '\'' +
", createtime=" + createtime +
'}';
}
} 着重看setCreatetime方法,完美解决,贴出来分享下小白吧,我自己也是小白。
明天找机会再分享下上传文件显示的问题,也当做给自己成长记录,同时做做笔记吧。
兴许以后会来看自己的代码会觉得可笑,但也挺值得回味的。
SpringMVC错误,商品添加信息HTTP Status 400 – Bad Request的更多相关文章
- SpringMVC格式转化错误之HTTP Status [400] – [Bad Request]
SpringMVC中,如果直接为Date类型的属性赋值,服务器有可能会报HTTP Status [400] – [Bad Request] Type Status Report Description ...
- springMVC 文件上传 HTTP Status 400 – Bad Request
可能原因是:multipartResolver没有配置正确 请看解决方案: <!--文件上传 id必须为multipartResolver,不然报错HTTP Status 400 – Bad R ...
- HTTP STATUS 400 – BAD REQUEST ,SPRINGMVC错误
400大多为前台传的数据于后台接受数据不符合,注意Date数据类型最容易错. 然后需要调用实体类的空参构造方法,,注意创建了有参构造方法后,创建一个空参构造方法.
- SSM搭项目报错:HTTP Status 400 – Bad Request
具体报错如下: Type Status Report Description The server cannot or will not process the request due to some ...
- jmeter接口测试 -- status==400(Bad Request)
一.接口请求信息 二.错误的jmeter接口请求 1.请求内容 2.响应内容 三.正确的接口请求 1.看回原本的接口请求信息,company_id = null .这里也就不能空 四.原因分析 1. ...
- HTTP Status 400 - Required request part 'file' is not present
今天使用Spring MVC做一个文件上传的功能,在提交表单的时候出现了如下错误:
- jersey HTTP Status 400 - Bad Request
原因是jersey 内置的转换器,只能做简单的类型转换如: 首先客户端提交上来的一定是String; String ----> String/Long/Boolean 这些基本的 可以转换,但是 ...
- Spring MVC出现POST 400 Bad Request &405 Request method 'GET' not supported
首先描述一下出现错误的情景: 我刚学springmvc,想做一个登录界面的东西.然后试着写了一个controller如下: @RequestMapping(value = "/login&q ...
- http status 400,http 400,400 错误
转载:http://blog.csdn.net/xu_zh_h/article/details/2294233 4 请求失败4xx 4xx应答定义了特定服务器响应的请求失败的情况.客户端不应当在不更改 ...
随机推荐
- DevOps - 总结
章节 DevOps – 为什么 DevOps – 与传统方式区别 DevOps – 优势 DevOps – 不适用 DevOps – 生命周期 DevOps – 与敏捷方法区别 DevOps – 实施 ...
- Tensorflow官方文档 input_data.py 下载
说明: 本篇文章适用于MNIST教程下载数据集. # Copyright 2015 Google Inc. All Rights Reserved. # # Licensed under the Ap ...
- P1063 计算谱半径
P1063 计算谱半径 转跳点:
- C# Chart 点击获取当前点击坐标和Series
C# Chart 点击获取当前点击坐标和Series https://blog.csdn.net/wumuzhizi/article/details/47168989 2015年07月31日 13:5 ...
- 搭建python的开发环境(采用eclipse的开发工具)在线和离线安装pyDev
一.首先下载python的开发环境并安装 在这里下载python3.7.2,然后安装在一个指定文件夹,随后,将安装路径配置到环境变量中 验证是否成功 OK! 二.在线安装pyDev工具 三.导入开发环 ...
- Day8 - A - Points on Line CodeForces - 251A
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. N ...
- 标准C的标记化结构初始化语法
1 struct file_operations { 2 struct module *owner; 3 loff_t (*llseek) (struct file * ...
- scan port
$sudo apt-get install nmap $nmap 127.0.0.1 Starting Nmap 7.60 ( https://nmap.org ) at 2020-02-20 15: ...
- node核心 http模块
node作为服务器更多的是web服务器 1.http模块 首先:http是一个协议.里面有通信机制,状态码一大堆乱七八糟的东西.自己写猴年马月都写不出来,这个对象帮我们集成.直接用 服务器对象: ht ...
- 基于Ambari的WebUI实现集群扩容案例
基于Ambari的WebUI实现集群扩容案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.将HDP的服务托管给Ambari服务 1>.点击“Service Auto S ...