list.jsp 页面  : <html:form action="/list?commpar=select">
类别:<html:select property="commodity.comtype" >
  <html:optionsCollection name="commodity.comType" label="typeName" value="typeId"/></html:select><html:submit value="查找"/> <html:submit value="增加"/>
</html:form>这样的提交为什么会出错,是关联的实体:public class Commodity {         //类型
Comtype comtype;    //get和set省略   商品中有个类型的属性
}      ActionForm:public class CommodityForm extends ActionForm {
   private Commodity commodity=new Commodity();public Commodity getCommodity() {        //actionform里有个商品的属性,上面的list.jsp 页面 <html:select>那样写 
                                          错了吗
return commodity;
}public void setCommodity(Commodity commodity) {
this.commodity = commodity;
}
}Action:public class CommodityAction extends DispatchAction { public ActionForward commManager(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
CommodityDao commdao=new CommodityDao();             //商品dao
ComtypeDao typedao=new ComtypeDao();                 //类型dao
List<Commodity> commoditys=commdao.selectAllComm();  //取出所有商品
 List<Comtype> comtypes =typedao.selectAllType();   //取出所有类型

 request.getSession().setAttribute("CommList",commoditys); //商品集合把放在session里
 request.getSession().setAttribute("comType", comtypes);   //类型集合把放在session里 return mapping.findForward("list");             //替转页面,这些都是为提到list.jsp 页面做的
}

public ActionForward select(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("哈哈哈哈哈哈哈哈哈哈哈哈哈");
return null;

}
   <struts-config>
  <data-sources />
  <form-beans>
  <form-bean name="CommodityForm" type="com.y2b2.Form.CommodityForm"/>
  </form-beans>
  .....................
  <action-mappings>
  <action path="/list" parameter="commpar" input="/index.jsp" type="com.y2b2.Action.CommodityAction" name="CommodityForm">
  <forward name="list" path="/MyJsp.jsp" ></forward>
 </action>
  </action-mappings>
   .................
</struts-config>
     

解决方案 »

  1.   

    帮帮忙啊 ,我都 搞这问题搞了一天了  就是<html:select property="commodity.comtype" > 
      <html:optionsCollection name="commodity.comType" label="typeName" value="typeId"/> 
    </html:select> 
    这段错误了
    <html:select property="commodity.comtype" >  //我是从actionform的commodity(商品)属性中的comtype(类型)属性绑定,也就是说商品有个comtype(类型)属性,而Actionform有个商品属性,comtype是commodity的一个关联类,我用hibernate关联着, 而<html:optionsCollection name="commodity.comType" label="typeName" value="typeId"/> //这句就是从Action中取出放在session中的comType(类型)集合,我发帖时写错了,
    在Action中是request.getSession().setAttribute("CommList",commoditys); //商品集合把放在session里 
    request.getSession().setAttribute("comType", comtypes);  //类型集合把放在session里 这样的,有个comType(类型)类,他有typeName,typeId两个属性 所以label属性是显示它的名字,value是显示它的Id
      

  2.   

    晕,你怎么能在网页中直接就用commodity.comtype
    怎么也要加个<%  %>啥的吧
      

  3.   

    运行 没问题  数据库的数据能取出来  可为什么 <html:form> 提交就出现javax.servlet.ServletException: BeanUtils.populate
    java.lang.IllegalArgumentException: Cannot invoke com.y2b2.Form.CommodityForm.setStudent - argument type mismatch
      

  4.   

    运行 没问题  数据库的数据能取出来  可为什么 <html:form> 提交就出现 javax.servlet.ServletException: BeanUtils.populate 
    java.lang.IllegalArgumentException: Cannot invoke com.y2b2.Form.CommodityForm.setStudent - argument type mismatch 
      

  5.   

     Cannot invoke com.y2b2.Form.CommodityForm.setStudent - argument type mismatch 参数类型搭配不当应该是在前台页面的值传到action里时setStudent类型出了问题。
      

  6.   

    呵呵  让我告诉你哪里错了把   <html:select property="commodity.comtype" > 
      <html:optionsCollection name="commodity.comType" label="typeName" value="typeId"/> 这两句错了,不信你试一试 commodity.comtype 这个 我想应该为commodity.comtype.typeId 为什么 因为 value="typeId" 这是你提交的值 这值摆明是comtype的typeId 你把值给了 commodity.comtype  不报
    参数类型搭配不当  才怪呢