*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JSP - UseBean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP - UseBean " Watch "JSP - UseBean " New topic
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.
 
Don't get me started about those stupid light bulbs.
 
subject: JSP - UseBean
 
Similar Threads
Mock exam question
jsp:useBean question
Java Beans
Reg useBean standard action
jsp:useBean Vs importing class file and using new