This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

page directive�s attributes

 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


?

tks.
 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone?
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

import="java.util.Date"
import='java.util.Date'

are valid, but:

import="java.util.Date'
import='java.util.Date"

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic