• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

a question need help

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question for Java Beans.
The contents of beans class are as follows:-

The contents of test.jsp file are as follows:

If a user types in http://servername:8080/test.jsp?name=Anand&age=22 the out put is

A The Name is Anand
The Age is 22
B
The Name is Null
The Age is 0

C It gives a compilation error as the properties are not set prior to retrieving them
D
The Name is null
The Age is null
which option is correct
and what's the difference between
<getProperty .../>
and <jsp:getProperty .../>
[Added CODE tags -- PdH]
[ October 31, 2002: Message edited by: Peter den Haan ]
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David:
My choice would be (B).
 
David Liu
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
would u please tell me the reason of choosing (B)
and the difference between <getProperty>
and <jsp:getProperty>?
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think B is the right choice. Cos' before the <jsp:getProperty> is called, the bean variable values are not set by the <jsp:setProperty> or any of its equivalent methods.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear David ,
The answer B is correct because the <jsp:getProperty> for age will give default value "0" (Had there been <jsp:setProperty > tag then answer would have been a ).
There is no defined tag <getProperty> may be it is typo error for (<jsp:getProperty> or it can be some custom tag .
Because instead of <jsp:getProperty> we can only use <%=test.getName()%> i.e. calling instance method of instance "test".
Hope this clears !
Regards,
Ajay Rana
SCJP,SCWCD
 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The correct answer given in the mock test is
The name is null
The Age is null
so exactly which is the correct answer?
Thanks,
Trupti
 
g madhava
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trupti,
The age is an primitive int and hence it would be initialized to 0 and not null.
 
David Liu
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in my tomcat
<getProperty name="test" property="name" />
or <jsp:getProperty name="test" property="name" />
has no output
but <jsp:getProperty name="test" property="age" />
output 0
and <getProperty name="test" property="age" />
has no output
why?
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David , Ajay said you tjere was no defined <getProperty> defined why do you write again <getProperty>, try with ..<jsp:getProperty>...
Good luck..
 
David Liu
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but <getProperty> does work in my tomcat
no translation error
no runtime error
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Has anyone tested it ?
and what is the outcome.
I just read the sybex book on this topic:
If you use the jsp:getProperty tag on a property whose value is equal to null, a NullPointerException is thorwn. If you are using a scriptlet or sxpression to retrieve this value, the null keyword is returned instead.
I will try next monday on an orion server. What is the outcome on other servers ?
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code usage <getProperty (without the jsp: ) , is wrong.

This code is right.

For both cases it may look like the browser is showing the exact same results. But then, if we right click on the browser and do view-source, we will see the difference.
For the 2nd case, what you see on the browser is what really sent to the browser. Meaning if you do view-source,

and the generated servlet code of the JSP is this :


Regards,
Maha Anna
[ November 25, 2002: Message edited by: Maha Annadurai ]
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic