• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The JSP page directive...

 
James Turner
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I have found this in the JSP 2.0 spec:


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. Multiple uses of the import attribute are cumulative (with ordered set union semantics). The pageEncoding attribute can occur at most once per file (or a translation error will result), and applies only to the file in which it appears.


Correct me if I'm wrong but I think that the spec is contradicting itself when it says that the pageEncoding attribute is exempt from the duplicate occurrences, as it then says that the pageEncoding attribute can occur at most once per file.

Does this mean the pageEncoding attribute if specified more then once, with different values will result in an error?

Thank you for your help.

Regards,
James.
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be honest with you I don't know about pageEncoding, but I can assure to you that you can have something like: <%@ page import="java.util.*" import="java.util.*" %> and that would be perfectly legal. Not only, this is a question which appears often in mock exams.
 
Nitish Bahadur
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James,

Consider a scenario where a JSP file is "included" using the JSP include directive. These are mainly used in case of Internationalization. For examples, /ja/*, where JA stands for Japan, might use Shift_JIS as its page encoding.

Additionally, I believe pageEncoding value should be the same as that of <page-encoding> in the <jsp-property-group>, if you have one defined.

Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic