Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes page directive�s attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "page directive�s attributes" Watch "page directive�s attributes" New topic

page directive�s attributes

Steven Colley
Ranch Hand

Joined: Feb 18, 2005
Posts: 290
Would be possible to do this:

<%@page import="java.util.Date" import='java.sql.*' %> , right?
(repeated import attributes with double ans single quotes..)

But and what about this : (within the same page)

<%@page import="java.util.Date" contentType="text/html" %>
<%@page import="java.sql.*" contentType="text/html" %>

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
Steven Colley
Ranch Hand

Joined: Feb 18, 2005
Posts: 290
Charles Lyons
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
I am a bit confused by the question, so I hope this clears it up anyway:

A pair of single quotes around attribute values is the same as a pair of double quotes, although doubles are much more common, but you must not mix the two for the same attribute value. So:


are valid, but:


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 / Amazon Amazon UK )
I agree. Here's the link:
subject: page directive�s attributes
It's not a secret anymore!