<form-bean name="commentForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="title" type="java.lang.String"/>
<form-property name="content" type="java.lang.String"/>
<form-property name="photoId" type="java.lang.String"/>
</form-bean><action path="/addComment" scope="request" type="angus.action.CommentLinkAction">
<forward name="success" path="/WEB-INF/jsp/display.jsp"/>
</action><bean name="/addComment" class="angus.action.AddCommentAction">
<property name="cs" ref="clientService"/>
</bean>具体代码如下
package angus.action;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.DynaActionForm;
import java.util.List;
import angus.service.root.ClientService;
import angus.vo.ClientVO;
import angus.tools.date.DateUtil;public class AddCommentAction extends Action
{
private ClientService cs; public void setCs(ClientService cs)
{
this.cs = cs;
} public ActionForward execute(ActionMapping mapping, ActionForm form, 
HttpServletRequest request, HttpServletResponse response)throws Exception
{
ClientVO cvo = (ClientVO)request.getSession().getAttribute("clientInfo");
DynaActionForm commentForm = (DynaActionForm)form;
String title = (String)commentForm.get("title");
String content = (String)commentForm.get("content");
String addTime = DateUtil.getFormalTime();
Integer photoId = Integer.valueOf((String)commentForm.get("photoId"));
Integer clientId = Integer.valueOf(cvo.getId());
cs.addPhotoWord(title, content, addTime, photoId, clientId);
ActionForward af = new ActionForward("/seecomment.do?photoId=" + String.valueOf(photoId));
return af;
}
}<%@ page contentType="text/html; charset=gb2312" language="java" %>
<%@ include file="taglibs.jsp"%>
<html:form action="addComment.do" onsubmit="return validateCommentForm(this)">
  <table width="100%"  border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="40" height="30">&nbsp;</td>
      <td width="150" class="sayabout">我要评论</td>
    </tr>
    <tr>
      <td height="20" class="Statistic2">标题:</td>
      <td><input name="title" type="text" class="input" size="15"></td>
    </tr>
    <tr>
      <td height="20" class="Statistic2">内容:</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><textarea name="content" cols="23" rows="5" class="input3"></textarea></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="hidden" name="photoId" value="${requestScope.photo.id}"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;&nbsp;&nbsp;<input name="Submit" type="submit" class="input" value="发表评论">        </td>
    </tr>
  </table>
</html:form>

解决方案 »

  1.   


    <form-bean name="commentForm" type="angus.action.AddCommentAction"> 
    </form-bean> 
    public class AddCommentForm extends ActionForm { private static final long serialVersionUID = 2157164832010287831L;
            private String title;
            private String content;
            private String photoId;        /**
                 getter和setter方法省略
            */ public ActionErrors validate(ActionMapping mapping,
    HttpServletRequest request) {
    // TODO Auto-generated method stub
    return null;
    } public void reset(ActionMapping mapping, HttpServletRequest request) {
    // TODO Auto-generated method stub
    }
    }
      

  2.   

        你的这句异常,应该是formBean里的属性和页面上的控件名没有对应上,认真对一下,应该能找出来。
      

  3.   

    Cannot retrieve definition for form bean null on action , 说明你的bean是空的, 并没有把formbean映射到action中,
    同普通ActionForm一样,Action类和JSP都可访问动态ActionForm,而访问方法也基本一致。访问动态ActionForm与访问普通ActionForm的最大区别在于对属性的访问方式不同。在标准ActionForm中,针对每个属性都提供了getter和setter方法,来读取和设置属性。而DynaActionForm把所有的属性保存在一个Map对象中,因此访问DynaActionForm中的属性与访问Map对象中的方法类似.<action path="/addComment" scope="request" type="angus.action.CommentLinkAction"> 
    这里缺少了一个name="commentForm"<action path="/addComment" name="commentForm" scope="request" type="angus.action.CommentLinkAction"> 
      

  4.   

    谢谢,不过如果不用mvc模块,而只是一个注册界面的话是不是就不能显示了?