Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

jsp:getProperty

 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am having 2 doubts.
1. Related to Anand Chawla 's Mock
Q 48 :-
If I am having two properties for a bean
say
int age ;
String name ;
If I am not setting these properties in JSP page but I am trying to get these using getProperty
e.g.
<jsp:getProperty name="name1" property="age">
<jsp:getProperty name="name1" property="name">
I think the result for age and name should be 0 and null
But exam answer specifies it as
null and null

2.
Consider the following line in JSP page ....... assume body-content as EMPTY
<x:foo><%-- any comment --%></x:foo>
Tomcat does not permit it as Empty tag , whereas
I think as per JSP Spec it should be treated as empty tag.
Please refer JSP.2.3.4 Empty Elements of JSP Spec
which states that
"
As examples, the following are all empty tags:
<x:foo></x:foo>
<x:foo />
<x:foo/>
<x:foo><%-- any comment --%></x:foo>
"
Please advice where am I going wrong???
Thanks
Buggi.
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For age it is 0 (at least in my browser), for name it should be null, but in browser nothing is printed... :-(
Anymore help in this issue?
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
**********************************
Q 48 :-
If I am having two properties for a bean
say
int age ;
String name ;
If I am not setting these properties in JSP page but I am trying to get these using getProperty
e.g.
<jsp:getProperty name="name1" property="age">
<jsp:getProperty name="name1" property="name">
***********************************
-----------------------------------
I tried the above JSP code with a JavaBean class. I got the following answer on my browser:
Name
Age 0
-----------------------------------
Thambi
 
Nazmul Huda Sarkar
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But in the following jsp code the uninitialized string prints null.
<%! String userName; %>
<%= userName %>
so, in the Bean the uninitialized string should also print null...
 
Nazmul Huda Sarkar
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q.2 Specs says that
<foo><!-- a comment --></foo> is an invalid empty Tag but <x:foo><%-- any comment --%></x:foo> is a valid empty Tag.
Did you miss something on % and !
I didn't check this in Tomcat yet...
[ September 01, 2002: Message edited by: Nazmul Huda Sarkar ]
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Even in orion <just:Tag><%-- empty implementation --%></just:Tag> is not accepted.
 
Nazmul Huda Sarkar
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just test the empty tag issue in Tomcat and does not work when a comment is added... :roll: :roll: :roll:
So..then what about SUN Specs
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regarding the question, why null is not printed , the null value is massaged with another method. Here is the code, I have taken out of the generated servlet code for the jsp. I used Tomcat to test this.
out.print(JspRuntimeLibrary.toString((((canopy.AddressBean)pageContext.findAttribute("address")).getStreet())));
I think JspRuntimeLibrary.toString() method takes care of null vaues, and return an empty String instead of null.
Regards,
Maha Anna
[ November 30, 2002: Message edited by: Maha Annadurai ]
 
Put a gun against his head, pulled my trigger, now he's dead, that tiny ad sure bled
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic