can't find bean preIndexForm in any scope

来源:百度知道 编辑:UC知道 时间:2024/05/29 15:15:12
我在一个jsp页面中写了以下内容
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<bean:define id="compInfo" name="preIndexForm" property="compinfoInfo" type="com.epportal.manageside.busiinfo.CompinfoInfo"/>

我的struts-config文件是这样写的
<form-bean name="preIndexForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="compinfoInfo" type="com.epportal.manageside.busiinfo.CompinfoInfo" />
</form-bean>

<action path="/preIndex" type="com.epportal.manageside.clientaction.PreIndexAction" name="preIndexForm">
</action>
我的struts 支持 dynaactionform

程序执行的时候报错 总是说Cannot find bean preIndexForm in any scope

在动态ActionForm声明的时候,属性tpye的值是struts提供的org.apache.struts.action.DynaActionForm
struts会自动调用这个类来进行封装,所以只要在*.xml文件里配置好就可以了,不用再写一个继承ActionForm的类。

动态ActionForm的优点是:如果在页面上添加了一个request(例如:让用户输入信息的文本框)的话,直接改*.xml文件就可以了,而静态ActionForm就要再编译.java文件,重启服务器才能有效。

缺点是:不能在*.jsp文件中用EL语句了(${}),如果要在*.jsp页面上用到form的话,就要在Action类的execute()方法中进行强转:
DynaActionForm dForm = (DynaActionForm)form;

然后用DynaActionForm中的get()方法,方法中传<form-property/>标签中属性name的值来获得封装request的数据。如果页面多的话,代码量会非常的大,所以一般在实际项目中都不会用到动态ActionForm。

下面是一个例子:
作用是在struts-config.xml配置了一个动态ActionForm,然后通过Action类把form转发到页面上。

struts-config.xml的配置:
<form-bean name="dform" type="org.apache.struts.action.DynaActionForm">
<form-property name="name" type="java.lang.String"/>
</form-bean>

Action类中execute()方法:
DynaActionForm dForm = (DynaActionForm)form;
String dName = (String)dFor