public class mybean { public mybean(int x,int y) {} }调用这个bean是怎么传入x,y,谢谢!
如果不是一定要这样做,建议用方法给其中的成员变量赋值, public class mybean { int x, y; public void setXY(int x, int y) { this.x = x; this.y = y; } }
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的代码,重新编译)?
{
public mybean(int x,int y)
{}
}调用这个bean是怎么传入x,y,谢谢!
public class mybean
{
int x, y;
public void setXY(int x, int y)
{
this.x = x;
this.y = y;
}
}
我在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的代码,重新编译)?
<jsp:usebean >
<some java code>
</jsp:usebean>