使用struts的<html:form>标签,抛出Cannot retrieve definition for form bean null on action Cart.do异常。
jsp页:
<html:form action="Cart.do" method="post">
<table>
<tr>
<th>
<b>Item ID</b>
</th>
<th>
<b>Product ID</b>
</th>
struts-comfig.xml配置:
<action path="/Cart"
type="test.frankco.web.actions.CartAction"
scope="request"
parameter="method">
<forward name="VIEW_CART" path="/jsp/cart/Cart.jsp"></forward>
</action>
原来,当我们使用html的<form >时,不需要配置struts的form-beans可以正常使用;
但如果要使用struts的<html:form>标签,则一定要配置form-beans,并制定配置到相应的action
struts-config.xml配置修改如下;
<form-beans>
<form-bean name="cartItemForm" type="test.frankco.web.forms.CartItemForm"></form-bean>
</form-beans>
...
<action path="/Cart"
type="test.frankco.web.actions.CartAction"
scope="request"
parameter="method"
name="cartItemForm">
<forward name="VIEW_CART" path="/jsp/cart/Cart.jsp"></forward>
</action>
加上cartItemForm的配置。
表示form表单与继承了ActionForm的表单元素与cartItemForm的属性一一对应,提交<html:form>表单时,struts会将表单的值自动填充到cartItemForm对应的属性中。
本文详细介绍了在使用Struts框架时,如何正确配置HTML表单与ActionBean之间的关联,避免出现无法获取定义的错误。通过提供具体的配置示例和解释,帮助开发者解决在开发过程中遇到的常见问题。
1059

被折叠的 条评论
为什么被折叠?



