• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a question need help

 
David Liu
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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 ]
 
g madhava
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David:
My choice would be (B).
 
David Liu
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would u please tell me the reason of choosing (B)
and the difference between <getProperty>
and <jsp:getProperty>?
 
Rohit Kelkar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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.
 
AJAY RANA
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • 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
 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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?
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
but <getProperty> does work in my tomcat
no translation error
no runtime error
 
friso jonge
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • 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 ?
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic