File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Java Beans 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 "Java Beans" Watch "Java Beans" New topic

Java Beans

harikumar devandla

Joined: Nov 26, 2004
Posts: 10
Consider the following .jsp file.


<%@ page language="java" import="com.mypackage.MyBean" %>
<jsp:useBean id="myBean" class="MyBean"/>
<jsp:setProperty name="myBean" property="myProperty" value="<%=request.getParameter("sentProperty")%>"/>
<jsp:getProperty name="myBean" property="myProperty"/>

Package com.mypackage;

Public class MyBean
private String myProperty;

public MyBean()

public MyBean(String myProperty)
this.myProperty= myProperty;}

public void setMyProperty(String myProperty)
this. MyProperty= myProperty;

public String getMyProperty()
return myProperty;

Which of the following is the result produced when MyUseBean.jsp is accessed with the URL
(With out any value provided to sentProperty)

Can you please tell me what is the answer?
I guess the answer'd be compilation error. because this("initial value")
should not be used with the constructor for the bean class.
As it a public no args constructor.

kindly waiting for the reply.
Gabriel Forro
Ranch Hand

Joined: Apr 16, 2004
Posts: 59

the Bean's code is all right. There is a no arg constructor, so it should be compiled without any error (You can call another constructor by the this(...) expression from the very first line of the constructor)

The final value of myProperty should be an ampty string. The reason is, that You have used the <jsp:setProperty.../>'s value form, where value is an empty string.

Nitish Bahadur
Ranch Hand

Joined: Aug 25, 2003
Posts: 118
Don't we need a fully qualified class name:
<jsp:useBean id="myBean" class="com.mypackage.MyBean"/>

Ignoring all compilation errors, I agree with Forro.

Joined: Oct 11, 2004
Posts: 12
I am beginner of JSP. but just wonder << language="java" >> is legal or not. becuase I never see it from the book. Please advise.

SCJP 1.4 SCWCD 1.4 (preparing)
I agree. Here's the link:
subject: Java Beans
It's not a secret anymore!