This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes HELP! Weird Include problem! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HELP! Weird Include problem!" Watch "HELP! Weird Include problem!" New topic
Author

HELP! Weird Include problem!

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
I'm using tomcat 4.1.18. When I used tomcat 3.2 I had no problem with this. Here's what I discovered:
When I include a page (has a teeny bit of JSP code, but mostly houses JavaScript code for client-side) as such:
<jsp:include page="/includes/header.jsp" flush="true" />
It only includes the bottom half of that header file. So half my javascript doesn't show up.
If i use the following:
<%@ include file="/includes/header.jsp" %>
I get a buffer overflow.
If I use the following:
<% getServletConfig().getServletContext().getRequestDispatcher( "/includes/header.jsp" ).include( request, response ); %>
NO PROBLEM AT ALL! Why is this?
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Tomcat 3.2 was a bit more forgiving (which it shouldn't have been) about mal-formed JSP tags. One example I can think of in my own past, was that I was forgetting to put the /> to end a singleton tag, but 3.2 didn't care.

Once I moved to 4.x it took forever and a day to figure it out.

Is the tiny bit of JSP in that included page behaving ? are you sure?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Another possibility is whether it is resulting in static or dynamic includes.
Sometimes an include statement results in a C style #include, where the JSP code is added to the same source file and there is a single Class output.
Dynamic includes create a separate Class for each JSP, execute them separately and then concatenate the output.
I'm not going to guess on the behaviour in your case, it's relatively vendor specific and just a useful thing to keep in mind.
There are pro's and con's to both but it is a long discussion and may have been discussed before. I recommend a search first.
Hope this helps you out though...
Dave
Marty Hall
Author
Ranch Hand

Joined: Jan 02, 2003
Posts: 111
Sometimes an include statement results in a C style #include, where the JSP code is added to the same source file and there is a single Class output.
Dynamic includes create a separate Class for each JSP, execute them separately and then concatenate the output.
I'm not going to guess on the behaviour in your case, it's relatively vendor specific and just a useful thing to keep in mind.

Actually, this is not vendor specific.
The jsp:include action includes the output of the included page. The included page gets invoked at request time. The main page and the included page are two separate servlets.
The @include directive includes the source of the included file. The included file gets merged into the main file at page-translation time. The main page and the included file become one big servlet.
Cheers-
- Marty
[ February 13, 2003: Message edited by: Marty Hall ]

Java training and consulting
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
marty,
sure, but why does it result in buffer overflow as @include but not jsp:include?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Originally posted by Marty Hall:
Actually, this is not vendor specific.

You're right, but it still relyies on the vendor implementing it correctly. I still tend to refer to it as vendor specific so that people don't just accept the behaviour without trying it out on their container first.
We're talking a few years now, but the behaviour of this changed dramatically in the BEA WebLogic server (4.51 and 5.1, I think).
Originally posted by Robert Paris:
sure, but why does it result in buffer overflow as @include but not jsp:include?

I'm not Marty but have you tried debugs to trace the flow? I can't think of anything off the top of my head to casue this (but then I'm still grogy from surgery yesterday), it would be pretty specific to your code.
Did you want to drop some sample code for us?
Dave
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
Basically in the include file all I have is:
(In bang definition, i.e. with a !)
1. String arrays holding global info like state names
2. method to check login
(regular)
1. HTML
2. JavaScript Code
What's weird is, if I remove the JAVASCRIPT code I don't get a buffer overflow!! What's up with that? Granted there is alot of JavaScript code, but still, isn't that weird?
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
post your code, it will make your problem easier to understand


Asher Tarnopolski
SCJP,SCWCD
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Robert, could you define "alot"?
[ February 14, 2003: Message edited by: Mike Curwen ]
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
sure. If I put the javascript alone into a text file, it's 14K.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HELP! Weird Include problem!
 
Similar Threads
Problem with include tag
Problem with include tag
JSP Components
include page directives
JSP file Include path fails with tomcat 6.0