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 ]
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
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
posted 17 years ago
Trupti, The age is an primitive int and hence it would be initialized to 0 and not null.
posted 17 years ago
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?
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 ?
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 ]