记录一个自己在做商品信息显示与传递数据的时候出现的错误,

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的更多相关文章

  1. SpringMVC格式转化错误之HTTP Status [400] – [Bad Request]

    SpringMVC中,如果直接为Date类型的属性赋值,服务器有可能会报HTTP Status [400] – [Bad Request] Type Status Report Description ...

  2. springMVC 文件上传 HTTP Status 400 – Bad Request

    可能原因是:multipartResolver没有配置正确 请看解决方案: <!--文件上传 id必须为multipartResolver,不然报错HTTP Status 400 – Bad R ...

  3. HTTP STATUS 400 – BAD REQUEST ,SPRINGMVC错误

    400大多为前台传的数据于后台接受数据不符合,注意Date数据类型最容易错. 然后需要调用实体类的空参构造方法,,注意创建了有参构造方法后,创建一个空参构造方法.

  4. SSM搭项目报错:HTTP Status 400 – Bad Request

    具体报错如下: Type Status Report Description The server cannot or will not process the request due to some ...

  5. jmeter接口测试 -- status==400(Bad Request)

    一.接口请求信息 二.错误的jmeter接口请求 1.请求内容 2.响应内容 三.正确的接口请求 1.看回原本的接口请求信息,company_id = null  .这里也就不能空 四.原因分析 1. ...

  6. HTTP Status 400 - Required request part 'file' is not present

    今天使用Spring MVC做一个文件上传的功能,在提交表单的时候出现了如下错误:

  7. jersey HTTP Status 400 - Bad Request

    原因是jersey 内置的转换器,只能做简单的类型转换如: 首先客户端提交上来的一定是String; String ----> String/Long/Boolean 这些基本的 可以转换,但是 ...

  8. Spring MVC出现POST 400 Bad Request &405 Request method 'GET' not supported

    首先描述一下出现错误的情景: 我刚学springmvc,想做一个登录界面的东西.然后试着写了一个controller如下: @RequestMapping(value = "/login&q ...

  9. http status 400,http 400,400 错误

    转载:http://blog.csdn.net/xu_zh_h/article/details/2294233 4 请求失败4xx 4xx应答定义了特定服务器响应的请求失败的情况.客户端不应当在不更改 ...

随机推荐

  1. Git安装及基本配置

    一.在Linux上安装 1.Linux系统安装 使用Linux发布版包含的基础软件包管理工具可以很容易安装Git.例如,在Ubuntu系统上可使用以下指令安装Git: $ sudo apt-get i ...

  2. Wincc V7.3SE安装截图

    打开某个工程出错,能力所限,找不到问题,没能解决

  3. springboot内嵌定时任务使用及cron表达式讲解

    第一步:pom引入依赖 <dependencies> <dependency> <groupId>org.springframework.boot</grou ...

  4. PAT (Advanced Level) 1144~1147:1145Hash二次探查 1146拓扑排序 1147堆

    1144 The Missing Number(20 分) 题意:给定N个数的序列,输出不在序列中的最小的正整数. 分析: 1.给定的N个数可能为正,可能为负,可能重复. 2.由于N≤10​5​​,所 ...

  5. 【蓝桥】第八届C语言C组第7题 Excel地址(进制变形题,stack()简单使用)转载

    标题: Excel地址 Excel单元格的地址表示很有趣,它使用字母来表示列号. 比如, A表示第1列, B表示第2列, Z表示第26列, AA表示第27列, AB表示第28列, BA表示第53列, ...

  6. Vue(九)---自定义指令(directive )

    1.无参数 自定义指令的方式:1. 使用Vue.directive 来自定义2. 第一个参数就是 指令名称 xart3. el 表示当前的html dom对象4. 在方法体内就可以通过 innerHT ...

  7. Consul 简介及集群安装

    简介 Consul是基于GO语言开发的开源工具,主要面向分布式,服务化的系统提供服务注册.服务发现和配置管理的功能. Consul的功能都很实用,其中包括:服务注册/发现.健康检查.Key/Value ...

  8. lamp-module

    要求:    (1) 三者分离于两台主机: (2) 一个虚拟主机用于提供phpMyAdmin:另一个虚拟主机用于提供wordpress: (3) xcache (4) 为phpMyAdmin提供htt ...

  9. SSM文件上传要点总结

    文件的上传要点: 1.表单方面:enctype="multitype/form-data" 编码方式选择混编码 input 类型采用file 2.实体类一定要进行序列化,也就是im ...

  10. Sass - &引用父选择器

    描述: 您可以使用&字符选择父级选择器. 它告诉父选择器应该插入的位置. 例一:&在前 h3 { font-size: 20px margin-bottom: 10px &.s ...