• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Is this not a valid JSP fragment?

 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was just going thro' one of the mock exam. Wherein it asked, choose the valid jsp code fragment

1) <%@ page import = "java.util.*" autoFlush="true" %>
<%@ page import = "java.io.*" autoFlush="true" %>

2) etc etc....

It says option 1) is wrong because, any page directive except import can only occur once.

I think its a valid JSP fragment. And autoFlush is nothing to do with this, as autoFlush is true by default.

Regards
Vishwas Hegde
 
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Sun's site

You can use the <%@ page %> directive more than once in a translation unit, but you can only use each attribute, except import, once. Because the import attribute is similar to the import statement in the Java programming language, you can use a <%@ page %> directive with import more than once in a JSP file or translation unit.

So I feel above code fragment is not valid.
[ March 08, 2006: Message edited by: KJ Reddy ]
 
Vishwas Hegde
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


you can use a <%@ page %> directive with import more than once in a JSP file or translation unit.

So I feel above code fragment is not valid.




[ March 08, 2006: Message edited by: Vishwas Hegde ]
 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What he said is you can use the page directive with the attribute import more than once. No problem.

But : you cannot use any other page directive attribute more than once.
It means, in your question, the autoFlush attribute is used twice, which is bad.

The only page directive attribute you can use more than once is : import.
 
Vishwas Hegde
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks

Regards
Vishwas
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

But : you cannot use any other page directive attribute more than once.
It means, in your question, the autoFlush attribute is used twice, which is bad.



You can use import and pageEncoding attributes more than one in a translation unit. But pageEncoding can use only once per file ( translation unit can have multiple files).

Any other attributes can appear multiple times, if their values are same otherswise it is error.

So I think the above fragments are correct.


Thanks
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, time for a spec fragment :

A translation unit (JSP source file and any files included via the include
directive) can contain more than one instance of the page directive, all the
attributes will apply to the complete translation unit (i.e. page directives are
position independent). An exception to this position independence is the use of the
pageEncoding and contentType attributes in the determination of the page
character encoding; for this purpose, they should appear at the beginning of the
page (see Section JSP.4.1). 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. Other
such multiple attribute/value (re)definitions result in a fatal translation error if the
values do not match.



Quite verbose, huh?
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic