日期:2014-05-20  浏览次数:20936 次

Property 'title' not found on type org.apache.struts.action.DynaActionForm
练习DynaActionForm , struts-config.xml中 <form-bean> 中信息是这样写的
XML code
<form-bean name="houseInfoDynaForm" type="org.apache.struts.action.DynaActionForm">
               <form-property name="title" type="java.lang.String"/>           
               <form-property name="cityId" type="java.lang.Integer"/>
               <form-property name="streetId" type="java.lang.Integer"/>
               <form-property name="rent" type="java.lang.Double"/>
               <form-property name="room" type="java.lang.Integer"/>
               <form-property name="hall" type="java.lang.Integer"/>
               <form-property name="houseType" type="java.lang.Integer"/>
               <form-property name="houseInfo" type="java.lang.String"/>
               <form-property name="telephone" type="java.lang.String"/>
               <form-property name="contactName" type="java.lang.String"/>
    </form-bean>

对应的PostAction 配置中 , name 属性也修改为HouseInfoDynaForm 。
XML code
<action
      name="houseInfoDynaForm"
      path="/jsps/post"
      type="org.zero.space.action.PostAction">
      <forward name="login" path="/jsps/login.jsp" />
      <forward name="confirm" path="/jsps/Confirm.jsp" />
    </action>

在PostAction中的代码是这样写的
Java code
DynaActionForm houseInfoDynaForm = (DynaActionForm)form ;
                HouseInfo houseInfo = new HouseInfo();
        houseInfo.setContactName(houseInfoDynaForm.getString("contactName"));
        houseInfo.setHall((Integer)houseInfoDynaForm.get("hall"));
        houseInfo.setHouseInfo(houseInfoDynaForm.getString("houseInfo"));
        houseInfo.setHouseType((Integer)houseInfoDynaForm.get("houseType"));        
        houseInfo.setRent((Double)houseInfoDynaForm.get("rent"));
        houseInfo.setRoom((Integer)houseInfoDynaForm.get("room"));
        houseInfo.setStreetId((Integer)houseInfoDynaForm.get("streetId"));
        houseInfo.setTelephone(houseInfoDynaForm.getString("telephone"));
        houseInfo.setTitle(houseInfoDynaForm.getString("title"));


运行后报错 , 主要的错误是这样的
Java code
严重: Servlet.service() for servlet jsp threw exception
javax.el.PropertyNotFoundException: Property 'title' not found on type org.apache.struts.action.DynaActionForm
    at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:193)
    at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:170)
    at javax.el.BeanELResolver.property(BeanELResolver.java:279)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:60)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)


我也是初学这点 , 就是没看出错误出在哪里

------解决方案--------------------
houseInfo.setTitle(houseInfoDynaForm.getString("title"));改成houseInfo.setTitle(houseInfoDynaForm.get("title"));
------解决方案--------------------
探讨