tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rishi N" <rea...@hotmail.com>
Subject How is 'include' directive handled during jsp compilation?
Date Tue, 02 May 2000 18:34:59 GMT
Hi,
I'm currently using a third-party jsp which includes another jsp. Here is 
the code fragment of the first file('first.jsp'):
-------------------------------
<%@ page language="java" import="java.util.Enumeration" 
contentType="text/html;charset=ISO-8859-1" errorPage="mainError.jsp" %>

<html>
<head>
  <%@ include file="WEB/jsp/second.jsp" %>

</head>
-------------------------------

'second.jsp' actually uses the Enumeration class, but it does not import it 
explicitly. Consequently, when i access 'first.jsp', it tries to compile 
'second.jsp', but in the corresponding java file generated by the jsp 
engine('second.java'), "java.util.enumeration" is *not imported* and the 
compilation fails with the ClassdefnotFound exception. I was looking at the 
JSP specification v1.1,and here is what it says about the include directive:

"The include directive is used to substitute text and/or code at JSP page 
translation time. The <%@ include file="relativeURLspec" %> directive 
inserts the text of the specified resource into the .jsp file.
...."

I'm assuming that the "substitute" part above was the reason why the author 
of 'first.jsp' imported 'java.util.enumeration' in 'first.jsp', but failed 
to do it in 'second.jsp'.

what i've observed is that tomcat compiles every jsp file, even ones that 
are included, into separate class files. if the intent of the 'include' 
directive is to simply substitute the text of the included file, then i'm 
guessing that the compilation would not have failed, since 
'java.util.enumeration' is being imported in the 'first.jsp'.

My questions:

1. why is each jsp compiled individually, rather than creating the entire 
file and then compiling that?

2. How is an included jsp file compiled? is it the responsibility of      
the jsp engine to cascade imports through an 'include' chain? i.e. since 
'second.jsp' is included in 'first.jsp', should the second.java file that is 
generated contain all the imports specified in 'first.jsp'?

3. how should my particular problem be handled? if imports are not cascaded, 
does it mean that every "called" jsp file should import whatever it needs, 
without expecting anything from the "calling" jsp?
that could mean some major work for us, since i don't know how many other 
includes have been made in this manner.

4. what is the correct way to write a jsp, then? should every jsp be a  
self-contained unit, at least as far as imports are concerned?

thanks,
rishi
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


Mime
View raw message