This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I�ve heard that we could "only" utilize many "import" attributes.
But i got this from a mock:
B - Trasnlation will "fail" because "contentType" attribute of the page directive is repeated across the page sources. - (FALSE)
Answer - B is "incorrect" because while it isn�t wise to repeat the contentType attribute more than once in the same translation unit, as long as the values are the same whenever it appears, then NO ERROR WILL OCCUR.
SCJP | SCWCD | SCBCD | SCWSD 5 | SCEA (I) 1.4 | SCEA 5 | IBM SOA 669
are invalid, resulting in a translation error. It is legal to declare as few or as many import attributes on page directives anywhere in any JSP page.
You have to be more careful with other attributes; for example, contentType (when it doesn't declare a page encoding) can be declared anywhere you like provided that each occurrence has the same value - if not, a translation error occurs. This applies to the same "translation unit", so applies also to all pages included using the import directive. This is logical as, after all, why would you want one page to set the contentType to "text/html" and another to "text/plain", for example? Then which content is actually being used?
Furthermore, pageEncoding and contentType (when specifying encoding) must always appear at the top of a page (before any content is written) because they are used at translation time to interpret the character encoding used in the page. However, both may appear in different JSP components with different encoding values, because each page could be encoded differently before compilation...
It's all a bit confusing; try looking at section JSP.1.10.1 of the JSP 2.0 spec. - it's explanation is quite good to take notes from.
Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / AmazonAmazon UK )