*
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


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 "Java Beans" Watch "Java Beans" New topic
Author

Java Beans

harikumar devandla
Greenhorn

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

MyUseBean.jsp

<%@ 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"/>
MyBean.java

Package com.mypackage;

Public class MyBean
{
private String myProperty;

public MyBean()
{
this("initialValue");
}

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
MyUseBean.jsp?sentProperty=
(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.
Thanks
Gabriel Forro
Ranch Hand

Joined: Apr 16, 2004
Posts: 59
Hi,

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.


Gabriel
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.
Sharon
Greenhorn

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: http://aspose.com/file-tools
 
subject: Java Beans
 
Similar Threads
Mock exam question
JSP - UseBean
jsp:useBean question
Reg useBean standard action
Unable to assign value to Bean property using jsp expression