It's not a secret anymore!
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
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP - UseBean " Watch "JSP - UseBean " New topic

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")%>"/>

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.
I agree. Here's the link:
subject: JSP - UseBean
It's not a secret anymore!