我的hibernate有一个类,类里面有2个date类型的字段,在struts-config中配置了formBean,绑定到jsp页面的表单form,
如果我在页面上加了这2个字段就会报错,如果不加就成功,我把代码贴上来,大大们帮我看下什么问题,这个问题困扰我一天了Servicelog.hbm.xml中的配置<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.hpxx.hibernate.Servicelog" table="servicelog" catalog="hpxx">
<id name="serId" type="java.lang.Integer">
<column name="serId" />
<generator class="assigned" />
</id>
<many-to-one name="orderinfo" class="com.hpxx.hibernate.Orderinfo" fetch="select">
<column name="orderId" not-null="true" />
</many-to-one>
<many-to-one name="manager" class="com.hpxx.hibernate.Manager" fetch="select">
<column name="managerId" not-null="true" />
</many-to-one>
<property name="serBeginTime" type="java.util.Date">
<column name="serBeginTime" length="10" />
</property>
<property name="serEndTime" type="java.util.Date">
<column name="serEndTime" length="10" />
</property>
<property name="errorDescription" type="java.lang.String">
<column name="errorDescription" length="200" />
</property>
<property name="answerDescription" type="java.lang.String">
<column name="answerDescription" length="200" />
</property>
<property name="serContent" type="java.lang.String">
<column name="serContent" length="200" />
</property>
<property name="serState" type="java.lang.Integer">
<column name="serState" />
</property>
</class>
</hibernate-mapping>AbstractServicelog.java中的内容package com.hpxx.hibernate;import java.util.Date;import org.apache.struts.action.ActionForm;/**
* AbstractServicelog entity provides the base persistence definition of the
* Servicelog entity.
*
* @author MyEclipse Persistence Tools
*/public abstract class AbstractServicelog extends ActionForm implements java.io.Serializable { // Fields private Integer serId;
private Orderinfo orderinfo;
private Manager manager;
private Date serBeginTime;
private Date serEndTime;
private String errorDescription;
private String answerDescription;
private String serContent;
private Integer serState; // Constructors /** default constructor */
public AbstractServicelog() {
} /** minimal constructor */
public AbstractServicelog(Integer serId, Orderinfo orderinfo,
Manager manager) {
this.serId = serId;
this.orderinfo = orderinfo;
this.manager = manager;
} /** full constructor */
public AbstractServicelog(Integer serId, Orderinfo orderinfo,
Manager manager, Date serBeginTime, Date serEndTime,
String errorDescription, String answerDescription,
String serContent, Integer serState) {
this.serId = serId;
this.orderinfo = orderinfo;
this.manager = manager;
this.serBeginTime = serBeginTime;
this.serEndTime = serEndTime;
this.errorDescription = errorDescription;
this.answerDescription = answerDescription;
this.serContent = serContent;
this.serState = serState;
} // Property accessors public Integer getSerId() {
return this.serId;
} public void setSerId(Integer serId) {
this.serId = serId;
} public Orderinfo getOrderinfo() {
return this.orderinfo;
} public void setOrderinfo(Orderinfo orderinfo) {
this.orderinfo = orderinfo;
} public Manager getManager() {
return this.manager;
} public void setManager(Manager manager) {
this.manager = manager;
} public Date getSerBeginTime() {
return this.serBeginTime;
} public void setSerBeginTime(Date serBeginTime) {
this.serBeginTime = serBeginTime;
} public Date getSerEndTime() {
return this.serEndTime;
} public void setSerEndTime(Date serEndTime) {
this.serEndTime = serEndTime;
} public String getErrorDescription() {
return this.errorDescription;
} public void setErrorDescription(String errorDescription) {
this.errorDescription = errorDescription;
} public String getAnswerDescription() {
return this.answerDescription;
} public void setAnswerDescription(String answerDescription) {
this.answerDescription = answerDescription;
} public String getSerContent() {
return this.serContent;
} public void setSerContent(String serContent) {
this.serContent = serContent;
} public Integer getSerState() {
return this.serState;
} public void setSerState(Integer serState) {
this.serState = serState;
}}jsp页面form表单内容<form action="insertservice.do" method="post">
<table style="font-size:12px;" width="100%" cellpadding="0" cellspacing="0">
<tr class="headDiv">
<td colspan="2" style="text-align:left;" align="left">服务记录添加</td>
<td colspan="2" style="text-align:right;" align="right"><a onclick="closeAddService()">关闭</a></td>
</tr>
<tr>
<td>工单编号:</td>
<td><input type="text" name="orderId" id="orderId" readonly/></td>
<td>用户登录帐号:</td>
<td><input type="text" name="clientAccount" id="clientAccount"/></td>
</tr>
<tr>
<td>服务开始时间:</td><td><input type="text" name="serBeginTime" id="serBeginTime"/></td>
</tr>
<tr>
<Td valign="top">故障描述:</Td>
<td colspan="3">
<textarea style="overflow:hidden; width:500px; height:100px;" name="errorDescription" id="errorDescription"></textarea>
</td>
</tr>
<tr>
<td valign="top">解决方案:</td>
<td colspan="3">
<textarea style="width:500px; overflow:hidden; height:100px;" name="answerDescription" id="answerDescription"></textarea>
</td>
</tr>
<tr>
<td>备注:</td>
<td colspan="3" style="width:500px;"><input type="text" name="serContent" id="content" width="500px"/></td>
</tr>
<tr>
<td>是否解决问题:</td>
<td><input class="radio" type="radio" name="serState" value="1"/>是<input class="radio" type="radio" name="serState" value="0"/>否</td>
<td>是否需要挂起:</td>
<td><input class="radio" type="radio" name="up" value="是"/>是<input class="radio" type="radio" name="up" value="否"/>否</td>
</tr>
<tr>
<td colspan="4" style="text-align:center;">
<input type="submit" value="添加"/>
<input type="button" value="取消"/>
</td>
</tr>
</table>
</form>大大们,帮我看下啊
如果我在页面上加了这2个字段就会报错,如果不加就成功,我把代码贴上来,大大们帮我看下什么问题,这个问题困扰我一天了Servicelog.hbm.xml中的配置<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.hpxx.hibernate.Servicelog" table="servicelog" catalog="hpxx">
<id name="serId" type="java.lang.Integer">
<column name="serId" />
<generator class="assigned" />
</id>
<many-to-one name="orderinfo" class="com.hpxx.hibernate.Orderinfo" fetch="select">
<column name="orderId" not-null="true" />
</many-to-one>
<many-to-one name="manager" class="com.hpxx.hibernate.Manager" fetch="select">
<column name="managerId" not-null="true" />
</many-to-one>
<property name="serBeginTime" type="java.util.Date">
<column name="serBeginTime" length="10" />
</property>
<property name="serEndTime" type="java.util.Date">
<column name="serEndTime" length="10" />
</property>
<property name="errorDescription" type="java.lang.String">
<column name="errorDescription" length="200" />
</property>
<property name="answerDescription" type="java.lang.String">
<column name="answerDescription" length="200" />
</property>
<property name="serContent" type="java.lang.String">
<column name="serContent" length="200" />
</property>
<property name="serState" type="java.lang.Integer">
<column name="serState" />
</property>
</class>
</hibernate-mapping>AbstractServicelog.java中的内容package com.hpxx.hibernate;import java.util.Date;import org.apache.struts.action.ActionForm;/**
* AbstractServicelog entity provides the base persistence definition of the
* Servicelog entity.
*
* @author MyEclipse Persistence Tools
*/public abstract class AbstractServicelog extends ActionForm implements java.io.Serializable { // Fields private Integer serId;
private Orderinfo orderinfo;
private Manager manager;
private Date serBeginTime;
private Date serEndTime;
private String errorDescription;
private String answerDescription;
private String serContent;
private Integer serState; // Constructors /** default constructor */
public AbstractServicelog() {
} /** minimal constructor */
public AbstractServicelog(Integer serId, Orderinfo orderinfo,
Manager manager) {
this.serId = serId;
this.orderinfo = orderinfo;
this.manager = manager;
} /** full constructor */
public AbstractServicelog(Integer serId, Orderinfo orderinfo,
Manager manager, Date serBeginTime, Date serEndTime,
String errorDescription, String answerDescription,
String serContent, Integer serState) {
this.serId = serId;
this.orderinfo = orderinfo;
this.manager = manager;
this.serBeginTime = serBeginTime;
this.serEndTime = serEndTime;
this.errorDescription = errorDescription;
this.answerDescription = answerDescription;
this.serContent = serContent;
this.serState = serState;
} // Property accessors public Integer getSerId() {
return this.serId;
} public void setSerId(Integer serId) {
this.serId = serId;
} public Orderinfo getOrderinfo() {
return this.orderinfo;
} public void setOrderinfo(Orderinfo orderinfo) {
this.orderinfo = orderinfo;
} public Manager getManager() {
return this.manager;
} public void setManager(Manager manager) {
this.manager = manager;
} public Date getSerBeginTime() {
return this.serBeginTime;
} public void setSerBeginTime(Date serBeginTime) {
this.serBeginTime = serBeginTime;
} public Date getSerEndTime() {
return this.serEndTime;
} public void setSerEndTime(Date serEndTime) {
this.serEndTime = serEndTime;
} public String getErrorDescription() {
return this.errorDescription;
} public void setErrorDescription(String errorDescription) {
this.errorDescription = errorDescription;
} public String getAnswerDescription() {
return this.answerDescription;
} public void setAnswerDescription(String answerDescription) {
this.answerDescription = answerDescription;
} public String getSerContent() {
return this.serContent;
} public void setSerContent(String serContent) {
this.serContent = serContent;
} public Integer getSerState() {
return this.serState;
} public void setSerState(Integer serState) {
this.serState = serState;
}}jsp页面form表单内容<form action="insertservice.do" method="post">
<table style="font-size:12px;" width="100%" cellpadding="0" cellspacing="0">
<tr class="headDiv">
<td colspan="2" style="text-align:left;" align="left">服务记录添加</td>
<td colspan="2" style="text-align:right;" align="right"><a onclick="closeAddService()">关闭</a></td>
</tr>
<tr>
<td>工单编号:</td>
<td><input type="text" name="orderId" id="orderId" readonly/></td>
<td>用户登录帐号:</td>
<td><input type="text" name="clientAccount" id="clientAccount"/></td>
</tr>
<tr>
<td>服务开始时间:</td><td><input type="text" name="serBeginTime" id="serBeginTime"/></td>
</tr>
<tr>
<Td valign="top">故障描述:</Td>
<td colspan="3">
<textarea style="overflow:hidden; width:500px; height:100px;" name="errorDescription" id="errorDescription"></textarea>
</td>
</tr>
<tr>
<td valign="top">解决方案:</td>
<td colspan="3">
<textarea style="width:500px; overflow:hidden; height:100px;" name="answerDescription" id="answerDescription"></textarea>
</td>
</tr>
<tr>
<td>备注:</td>
<td colspan="3" style="width:500px;"><input type="text" name="serContent" id="content" width="500px"/></td>
</tr>
<tr>
<td>是否解决问题:</td>
<td><input class="radio" type="radio" name="serState" value="1"/>是<input class="radio" type="radio" name="serState" value="0"/>否</td>
<td>是否需要挂起:</td>
<td><input class="radio" type="radio" name="up" value="是"/>是<input class="radio" type="radio" name="up" value="否"/>否</td>
</tr>
<tr>
<td colspan="4" style="text-align:center;">
<input type="submit" value="添加"/>
<input type="button" value="取消"/>
</td>
</tr>
</table>
</form>大大们,帮我看下啊
<column name="serBeginTime" length="10" />
</property>
<property name="serEndTime" type="java.util.Date">
<column name="serEndTime" length="10" />
</property>
这里错了。
应该这样映射
<property name="registerDate" type="timestamp" column="registerdate"></property>
import java.sql.Date;private Date playerBirthday;<property name="playerBirthday" type="java.sql.Date">
<column name="player_birthday" length="23" />
</property>
<td>服务开始时间:</td><td><input type="text" name="serBeginTime" id="serBeginTime"/></td>
<td>服务结束时间:</td><td><input type="text" name="serEndTime" id="serEndTime"/></td>
</tr>但是,如果我加上这2个字段就会报错,不加这2个字段其他的字段都能获得到数据。
报的错误是:java.lang.IllegalArgumentException: Cannot invoke com.hpxx.hibernate.AbstractServicelog.setSerEndTime - argument type mismatch
at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1778)
at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1759)
at org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1648)
at org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:1677)
at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1022)
at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)
at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:816)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.hpxx.filter.EncodingFilter.doFilter(EncodingFilter.java:31)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
大大们帮帮忙
当输入页面中含有日期如2008-01-01时,如果Form中对于的字段为Date类型,则会出现“argument type mismatch”错误。 原因:
Struts的ActionServlet在接受到页面的请求后,会调用RequestUtils.populate方法对Form进行填值,而此方法又调用到BeanUtils.populate方法,而该方法进行填值时对不同类型的会进行转换,而默认的ActionServlet并没有注册相应的转换函数,所以会导致转换出现错误。
1.实现自定义的ActionServlet方法并在里面注册转换函数。
2.Form中的日期类型使用String类型,把转换动作放在Action中处理(即在Action中对Form->POJO转换时处理),可以在Action基类中注册类型转换类。
能告诉我怎样在ActionServlet中转换吗?
解决方法:
1.实现自定义的ActionServlet方法并在里面注册转换函数。
2.Form中的日期类型使用String类型,把转换动作放在Action中处理(即在Action中对Form->POJO转换时处理),可以在Action基类中注册类型转换类。 如果在Form中使用date类型,在jsp向form中填充的时候,是什么类型