难道javabean中的constructor不能有参数?

解决方案 »

  1.   

    public class mybean
    {
       public mybean(int x,int y)
       {}
    }调用这个bean是怎么传入x,y,谢谢!
      

  2.   

    如果不是一定要这样做,建议用方法给其中的成员变量赋值,
    public class mybean
    {
      int x, y;
      public void setXY(int x, int y)
      {
        this.x = x;
        this.y = y;
      }
    }
      

  3.   

    to:mty
    我在sun的网站上查了一下,发现jsp用的bean的constructor不能有参数:
    “In addition to the property methods, a JavaBeans component must define a constructor that takes no parameters.”用方法设置属性只能在bean实例化后设置,但我要的参数是bean实例化时需要的参数,不知有没有其他的机制(除了在bean的constructor中用具体的值,要改变值则改bean的代码,重新编译)?
      

  4.   

    jsp:usebean中指定的bean 不能有参数,你可以在
    <jsp:usebean   >
    <some java code>
    </jsp:usebean>
      

  5.   

    hehe,我这几天天天为这个问题苦恼。望高手谈谈看法。