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应答定义了特定服务器响应的请求失败的情况.客户端不应当在不更改 ...
随机推荐
- Redis使用守护进程启动sentinel并指定其日志目录
正常redis-server可以通过配置文件来指定守护进程启动以及指定日志路径,但sentinel就不一样了.正常启动redis的sentinel时,进程会直接在前台跑,一退出sentinel进程就关 ...
- hibernate通过数据库表反向生成实体类
步骤一: window-->open Perspective-->MyEclipse Java Persistence 进行了上面的 操作后会出现一个视图DB Brower:MyEcl ...
- Linux下四种安装软件方式
1.yum源安装 可以解决依赖关系,但不确定安装的位置 2.rpm 基础安装 要自己解决依赖问题 rpm -ivh 安装 rpm -uvh 更新 rpm -e --nodeps 卸载 取消依赖 ...
- 吴裕雄--天生自然JAVA数据库编程:JDBC操作步骤及数据库连接操作
public class ConnectionDemo01{ // 定义MySQL的数据库驱动程序 public static final String DBDRIVER = "org.gj ...
- Matplotlib 图形绘制
章节 Matplotlib 安装 Matplotlib 入门 Matplotlib 基本概念 Matplotlib 图形绘制 Matplotlib 多个图形 Matplotlib 其他类型图形 Mat ...
- arm linux 移植 udhcp 与 使用
背景 在一些网络环境下,需要静态IP不够现实,需要使用DHCP进行自动获取IP地址. udhcpc是一个面向嵌入式系统的非常小的DHCP客户端,字母的缩写微μ- DHCP -客户端client(μDH ...
- Ternsorflow 学习:001-通过例程,初步了解Tensorflow
前言 本章的目的是了解和运行 TensorFlow,在开始之前,让我们先看一段使用 Python API 撰写的 TensorFlow 示例代码,让你对将要学习的内容有初步的印象. 下面这段短小的 P ...
- ElasticSearch学习,入门篇(一)
概念解析 1.什么是搜索 搜索就是在任何场景下,找寻你想要的信息,这个时候你会输入一段要搜索的关键字,然后期望找到这个关键字相关的有效信息. 2.如果用数据库做搜素会怎么样 select * from ...
- Java数组去重的方法
//第一种方式:最开始想到的是利用Set集合的不可重复性进行元素过滤 public static Object[] oneClear(Object[] arr){ Set set = new Has ...
- GoJS、AngularJS自定义组件JS SDK注解参考
通常一个SDK包含一个或多个API 下面是一个SDK的实例: if (typeof(wlNgApp) === "undefined") wlNgApp = angular.modu ...