• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What does the following statement means?

 
Shashidhar Yarabati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any page directive except import can only occur only once.

Why the following JSP code wrong?
<%@ page import="java.util.*" autoFlush="true"%>
<%@ page import="java.io.*" autoFlush="false"%>

Can any body help me to understand this?
[ May 14, 2008: Message edited by: Shashidhar Rao ]
 
Shashidhar Yarabati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does the above means autoflush repeated twice, and this should not be done?

Am I right guys?
 
S Sravs
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you are right since import statement can be more than once in jsp page

Regards
Sravanthi
 
Ash More'
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, multiple occurences of attributes other then import is allowed, provided there values remain the same
For eg:
<%@ page import="java.util.*" autoFlush="true"%>
<%@ page import="java.io.*" autoFlush="true"%>

is allowed

whereas below is not allowed:
<%@ page import="java.util.*" autoFlush="true"%>
<%@ page import="java.io.*" autoFlush="false"%>

(the above gives the following error in tomcat 6
Page directive: illegal to have multiple occurrences of autoFlush with different values (old: true, new: false)
)
 
Shashidhar Yarabati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I saw some where that Any page directive except import can only occur only once.

Is it wrong???
 
John Pearson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page directives can occur multiple times, as long as the values are the same. The following is from the JSP 2.0 spec on page directives:

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.
 
Prasad Tamirisa
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Import is the page directive that is used to import different packages in to the jsp. Which means that you have as my page directive's as you want in a single directory.

But if you look at the other directives, almost all of them are to set a particular property corresponding to the jsp. There is not meaning in having two page directives with different values.

for example....
autoFlush if set to true,the buffer output will be flushed whenever the buffer is full and vice versa.


In this case, there is no meaning if you declare autoFlush two times with controversial values. So, your code mentioned above can be changed some like below.

1)



2)


You may want to check this usefull article about page directives. Hope this helps....
[ May 17, 2008: Message edited by: Prasad Tamirisa ]
 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ page import="java.util.*" autoFlush="true"%>
<%@ page import="java.io.*" autoFlush="false"%>

My understanding, the above two lines of code will be eventually interpreted as a single line, like below:
<%@ page import="java.util.*" autoFlush="true" import="java.io.*" autoFlush="false"%>

if you observe JSP spec, it mentioned that import can occur multiple times, other attributes can also occur multiple times but with same values.

if you change your code as blow :
<%@ page import="java.util.*" autoFlush="true"%>
<%@ page import="java.io.*" autoFlush="true"%>

it will be interpreted as :
<%@ page import="java.util.*" autoFlush="true" import="java.io.*"%>

which is leagal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic