Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help: valid declarations in a JSP page

 
Kelvin Hung
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I encounter a question on j2eecertificate and I don't understand the answer.
Which of the following are valid declarations in a JSP page? [Check all correct answers]


1) <jsp:getProperty Name="id" Property="streetName"/>
2) <jsp:getProperty property="streetName" name="id"></jsp:getProperty>
3) <jsp:getProperty name="id" class="com.baboon.scwcd.Address" property="streetName"/>
4) <jsp:getProperty name="id" property="streetName"/>
5) <jsp:getProperty property="streetName" name="id"/>

Answer is 4) and 5).
But why not 2)? 2) and 5) are the same, right?
Kelvin
[ January 15, 2004: Message edited by: Kelvin Hung ]
 
Mehdi Chaouachi
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think because the <jsp:getproperty> should be closed in the same tag like this <jsp:getProperty/> and not in a closing tag like this </jsp:getProperty> because the getProperty does not take any content between its opening and closing and instead it uses only attributes to define it s behavior.
Please correct me if I am wrong.
 
Kelvin Hung
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think a closing tag has to be in this format </tagName>
<jsp:getProperty> should take empty body, and I think 2) is equal to empty body, right?
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
 
hover cheng
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayadev Pulaparty,

JSP tag syntax does not permit for opening and closing tags with jsp:getProperty. You must provide a single tag that is 'self-closing.' Option 2 is therefore invalid syntax.

I have no idea where the JSP specification forbids using getProperty as <jsp:getProperty...></jsp:getProperty>. The only contraint I can find is that "getProperty" must has an "empty body". Per xml syntax, the "empty body" for an element can be presented as "<someElement/>", AND "<someElement></someElement>" as well.
I have tested both syntax for "getProperty" under Tomcat 5.0.16, and both work well.
 
Kelvin Hung
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup Hover, I would vote the answer of the question is wrong.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic