• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

page directive�s attributes

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
anyone?
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic