我所遇到的 Error creating form bean of class

所遇到的 Error creating form bean of class

相信在开发的过程中会有人遇到 Error creating form bean of class……之类的问题,每个人遇到这个问题的原因肯定是千奇百怪,不一而足,我这里只能说说 我所遇到的 Error creating form bean of class 问题,和对应的解决方法

 

我遇到这个问题的原因起源于: 一个action 对应多个form

struts.xml配置文件如下:

  
<form-bean name="CommentActionForm"
                    type="cn.ac.iscas.share.comment.actionform.CommentActionForm" />
<form-bean name="SeachCommentModel" 
                    type="cn.ac.iscas.share.comment.model.SeachCommentModel" />
……  
<action name="CommentActionForm" type="cn.ac.iscas.share.comment.action.CommentAction" 
             scope="request" parameter="method" path="/CommentAction" >
		<forward name="getModelComments" path="/pm/comment/getModelComments.jsp"/>
		<forward name="addComment" path="/pm/comment/commentTr.jsp"/>
		<forward name="findCommentList" path="/pm/comment/commentList.jsp"/>
   </action>
   <action name="SeachCommentModel" type="cn.ac.iscas.share.comment.action.CommentAction" 
                scope="request" parameter="method" path="/CommentAction1" >
		<forward name="findCommentList" path="/pm/comment/commentList.jsp"/>
   </action>

 

然后,有一个超链接 为http://localhost:8080/pm/CommentAction.do?method=findCommentList,通过 findCommentList 跳转到了commentList.jsp 页面,在commentList.jsp页码用 SearchCommentModel这个form来进行填充,对应的jsp代码如下:

 

<div class="searchdiv">
<html:form action="/CommentAction1.do" >

 

这样就产生了上面的错误,产生上面错误的原因有两个:

 

1、个人疏忽,原来的SearchCommentModel.java代码如下:

public class SeachCommentModel  {

	private boolean isRead = true;// 是否已读
	private Integer projectId;// 项目Id
	private String content;// 评论内容,模糊查询
	private Integer empId;// 评论人,
	private Date startDate;// 评论时间
	private Date endDate;// 评论时间

 

这个显然是错误的,既然在xml配置文件中声明了 SearchCommentModel是一个action from,但是在写代码的是很却没有extents actionform,正确的代码如下:

 

import org.apache.struts.action.ActionForm;
public class SeachCommentModel extends ActionForm {

	private boolean isRead = true;// 是否已读

 

2、因为超链接是http://localhost:8080/pm/CommentAction.do,是CommentAction.do,也就意味 着在调用这个action时,CommentAction对应的form CommentActionForm 被放在了request中,那么在对生成jsp页面时,从request中取到的时CommentActionForm,而不是 SeachCommentModel。

 

因此如果想在生成jsp页面时,能够从request中取到SeachCommentModel 的actionform,对应的超链接只能改为

http://localhost:8080/pm/CommentAction1.do 。也就是吧CommentAction 改成CommentAction1,这样就把CommentAction1对应的SeachCommentModel放到了request中,从而生成 jsp页面时就不会报错了。

 

 

两外,对于 html:radio的用法,正确的用法实例如下:

<html:radio name="SeachCommentModel" 
           property="isRead" value="false">未读</html:radio>&nbsp; 
<html:radio name="SeachCommentModel"
            property="isRead" value="true">已读</html:radio>
 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值