aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Question reagrding Beans.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Question reagrding Beans...." Watch "Question reagrding Beans...." New topic
Author

Question reagrding Beans....

Yati Tan
Ranch Hand

Joined: May 28, 2005
Posts: 56
Which of the following staments are correct about the following jsp lines:

<jsp:useBean id=�name� class=�java.lang.String� />

<%=name %>

1) It won't compile.
2) It is a valid jsp line and it will print the variable called name.
3) It will compile but it will always produce null as the output.
4) It will work if you create a javabean class with only one variable of type java.lang.String.


Pls reply, which one u all think is the best answer ?


SCJP 1.4<br />SCJA 1.0<br />SCWCD 1.4
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
I suppose option 3 is correct.


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
P Chittaranjan
Ranch Hand

Joined: Feb 09, 2006
Posts: 47
Option 1 is Correct. It won't compile the jsp page.


Thanks,<br />Chittaranjan<br />SCJP 5.0,SCWCD1.4,SCBCD 5
P Chittaranjan
Ranch Hand

Joined: Feb 09, 2006
Posts: 47
Sorry, I was wrong. Jsp page will compile.
For this question no output is there.

But if we will replace java.lang.String with java.lang.Object it will call the toString() method on name object and print the result.
We will get the output something like this:java.lang.Object@1d8f162

In both the cases, it will not print null.

As long as the class attribute contains some concreate class , we will get the output.

If the class attribute contains any Abstract class or Interface, we will get InstantiationException at run time.

Thanks
Chittaranjan
Yati Tan
Ranch Hand

Joined: May 28, 2005
Posts: 56
Well, the answer to above question is 2). It will not print nything. Chittranjan is right here. But, wen Iam running it on my server -its not getting compiled anyways. Can u help me more on this ?
P Chittaranjan
Ranch Hand

Joined: Feb 09, 2006
Posts: 47
Hi Yati,

You Should run the program exactly with wht written in the question.
If you have any <jsp:setProperty> and <jsp:getProperty>, it will not compile.

If you can give the jsp content, I can find out the problem.

Thanks
Chittaranjan
Yati Tan
Ranch Hand

Joined: May 28, 2005
Posts: 56
Chittaranjan,

Iam trying to run JSP code as :

<html>
<body>

<jsp:useBean id=�name� class=�java.lang.String� />

<%=name %>


</body>

</html>

Still, Iam getting error. Pls help, why Am I getting 500 Exception Report.
P Chittaranjan
Ranch Hand

Joined: Feb 09, 2006
Posts: 47
Hi Yati,

The quotes are not proper for id and class attribute.

Your : <jsp:useBean id=name class=java.lang.String />

Replace with this: <jsp:useBean id="name" class="java.lang.String" />

Thanks
Chittaranjan
Yati Tan
Ranch Hand

Joined: May 28, 2005
Posts: 56
Thanks. It was a typo. Code is running fine now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question reagrding Beans....
 
Similar Threads
JSP - UseBean
mock exam question
mock question
doubt in <jsp:usebean..
3 is correct ...but the answer states it is 2..am i right