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

mock question-page directive

 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Please have a look at this question:

Is the following JSP code legal? Select the one correct statement.
<%@page info="test page" session="false"%>
<%@page session="false"%>

A) Yes. This is legal JSP syntax.
B) No. This code will generate syntax errors

My answer is A. But they have stated correct answer as B.
What will be your answer?
 
Mohit Chadha
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is from the specifications:
There shall be only one occurrence of any attribute/value pair defined by this directive in a given translation unit, unless the values for the duplicate attributes are identical for all occurrences. The import and pageEncoding attributes are exempt from this rule and can appear multiple times.

Hence according to the specifications it should be A.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohit,

The answer should be B. Only the import attribute can appear any number of times in a jsp page.
 
Tim Storms
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't agree. When an attribute occurs more than once, it doesn't give an error when its value is the same. The import and pageEncoding attributes may occur multiple times.

The answer is A in my opinion.
 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All of you thank you very much for your replies
 
Kosala W.Abayagunawardene
Ranch Hand
Posts: 47
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Storms wrote:I don't agree. When an attribute occurs more than once, it doesn't give an error when its value is the same. The import and pageEncoding attributes may occur multiple times.

The answer is A in my opinion.




Page directive is used to specify a number of page specific attributes
such as content type, page encoding, classes to import and buffering
model etc. A translation unit can contain more than one instance of
page directive, in any order, anywhere and all attributes will be
applied together to the whole translation unit. However there are
few exceptions.

1. pageEncoding and contentType attributes must appear at the
beginning of the page.
2. An attribute must appear only once in a translation unit unless
the values of the attribute are same for all occurrences,
otherwise a translation error will occur. The import and
pageEncoding can appear more than once in a translation unit.
3. pageEncoding attribute can appear at most once per a file
otherwise a translation error will occur.

Note: A JSP source file and any other files included with include
directive is called the translation unit.
 
Hasnain Javed Khan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2. An attribute must appear only once in a translation unit unless
the values of the attribute are same for all occurrences,
otherwise a translation error will occur. The import and
pageEncoding can appear more than once in a translation unit.

Note: A JSP source file and any other files included with include
directive is called the translation unit.


So it means in



And in


would cause an error ?

Kind Regards.
Hasnain.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
Next time, try not to wake up zombies Thank you.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic