• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question reagrding Beans....

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose option 3 is correct.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Option 1 is Correct. It won't compile the jsp page.
 
P Chittaranjan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. It was a typo. Code is running fine now.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic