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

Strange question in mockup exam

 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have the following question in my mockup exam:
... you have to add a "count" instance variable to a critical JSP Document so that a JMX Bean can track how frequent this JSP is invoked. Which JSP code snippet you must use to declare this instance variable in the JSP Document?

A: <jsp:declaration>
int counti = 0;
<jsp:declaration>

B: <%! int count = 0; >

([C] and [D] are obviously wrong)

The mockup says A is right
Ok, even if the missing slash in the end tag is just a typo, i don't get what's wrong with B.
B looks like a proper declaration of a instance variable to me.

Does someone know the correct answer to this question?
Thanks Chris
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Chris!

Well, as far as I remember this part, the JSP Document is not allowed to use <%! construction. Scriptlets (<%), declarations (<%!), expressions (<%=), directives (<%@) or any "loose" text are not allowed. The document has to be an XML file, so:
- scriptlet is changed into <jsp:scriptlet></jsp:scriptlet>
- text is changed into <jsp:text></jsp:text>
- declaration is changed into <jsp:declaration></jsp:declaration>
... and so on - I think you should get the point.

Take a look at JSP 2.0 Specification, page 125 ("JSP Documents") [in my version: 2.2, Maintenance Release 2] for more detailed information.

Cheers!
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the key word is "JSP Document" here. #$&%! terminology
Thanks Pedro!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic