| Author |
JSP - UseBean
|
Jayashree Mohan
Ranch Hand
Joined: Nov 23, 2005
Posts: 37
|
|
Consider the following <%@ page language="java" import="com.mypackage.MyBean" %> <jsp:useBean id="myBean" class="MyBean"/> <jsp:setProperty name="myBean" property="myProperty" value="<%=request.getParameter("sentProperty")%>"/> MyBean.java Package com.mypackage; Public class MyBean { private String myProperty; public MyBean(String myProperty) { this.myProperty= myProperty; } public void setMyProperty(String myProperty) { this. MyProperty= myProperty; } public String getMyProperty() { return myProperty; } } Will this give a compilation/translation error? (Beans cannot have constructors with arguments)
|
 |
Akshay Kiran
Ranch Hand
Joined: Aug 18, 2005
Posts: 220
|
|
why don't you try it out? it should give an error, not because beans cannot have constructors with arguments, but because beans SHOULD have a no-arg constuctor or what will the container call when it needs to instantiate it?
|
 |
Vivek Kinra
Ranch Hand
Joined: Mar 11, 2006
Posts: 66
|
|
I agree with Akshay... A bean class must have a zero-argument (empty) constructor.You can satisfy this requirement either by explicitly defining such a constructor or by omitting all constructors, which results in an empty constructor being created automatically.
|
 |
 |
|
|
subject: JSP - UseBean
|
|
|