This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Including a JSP page from a different Web Application  RSS feed

 
Thambi Rajah
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to include a JSP page(Inner.jsp) from a Web application(examples)
into another JSP page(Outer.jsp) which is in a different Web application(demo).
The code for Outer.jsp and Inner.jsp are shown below:
Outer.jsp:

Inner.jsp:

Assume that Inner.jsp, Outer.jsp exist at root level of their corresponding Web Applications
examples, demo respectively.When I access the Outer.jsp by entering the URL:
http://localhost:8080/demo/Outer.jsp ,
I got the following output.

Inside Inner.jsp
Inside Outer.jsp

My question is the following:
I expected that "Inside Outer.jsp" would come first before "Inside Inner.jsp" in the output.
Why is the output order has reversed?
Thanks in advance,
Thambi
 
Harpartap Singh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RequestDispatcher.include() does not do a flush.
Try this instead, and the output should be in expected order:
Outer.jsp
 
Harpartap Singh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... Sorry previous was incomplete....
Outer.jsp
 
Thambi Rajah
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Mr. Harpartap Singh for your suggestion.
When I inserted pageContext.getOut().flush() in my code, it works fine with the right order of output. I am still not very clear how the flush() command makes the difference.

Thank you
Thambi
 
Sanjeev Kaushik
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried you example in Weblogic 6.1. And it showd the desired output.
Inside Outer.jsp
Inner.jsp
Sanjeev Kaushik
 
Harpartap Singh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I am using JRUN 4, development version and I reproduced the strange behavior. I even simplified the problem statement, you don't have to include a file from another web app.
Problem:
The call to RequestDispatcher.include() is producing two odd behaviors:
1. after return from rd.include(), the response.isCommitted() is "true". That baffles me. How did the committed status get set to true?
2. And at that point ALL the data from the included file ONLY has been flushed out. How can ONLY the data from included file's buffer make its way out to the browser, and the outside file's data is still waiting to be sent out?
The API clearly states that:
The ServletResponse object has its path elements and parameters remain unchanged from the caller's. The included servlet cannot change the response status code or set headers; any attempt to make a change is ignored.
Something smells fishy here.
Of course, <jsp:include> does not have any problem. It is behaving as expected in both cases: with flush set to true and false.

-----------------------
outer.jsp
-----------------------
<html> <body>

<h3>This is Outer.jsp</h3>
<%
RequestDispatcher rd = request.getRequestDispatcher( "/inner.jsp" );
rd.include( request,response );
%>
(outer.jsp) responseCommitted=<%=response.isCommitted()%>
</body></html>

------------------
inner.jsp
-----------------
<html><body>
<h>Inside inner.jsp - <h>
(inner.jsp) responseCommitted=<%=response.isCommitted()%>
</html></body>

---------
OUTPUT
---------
Inside inner.jsp - - (inner.jsp) responseCommitted=false
This is Outer.jsp
(outer.jsp) responseCommitted=true

------------
Expected CORRECT OUTPUT should have been, produced using <jsp:include page="inner.jsp" flush="false" /> INSTEAD of rd.include()
-------------
This is Outer.jsp
Inside inner.jsp - - (inner.jsp) responseCommitted=false
(outer.jsp) responseCommitted=false
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The one factor that hasn't been mentioned is that access to web applications typically occurs through a thread pool.
The effect that has is that when you reach from one web app to another, you want to concatenate the outputs, but you don't have any control over how they get written to the output stream since they are being processed on separate threads.
The other side is that it would be highly vendor specific. I disagree with trying to reach between web apps in this way, but we did manage to get it working in WebSphere a while ago.
 
Harpartap Singh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,
I could understand when dealing with "different" web applications. But I am reproducing this on the SAME application.
The question then is, is RequestDispatcher.include()[SAME APPLICATION] spawning a new thread, with its own output stream, AND flushing the data ONLY from this new stream?
That doesn't seem correct?
It appears this problem has been talked about earlier in other forums, and someone suggested that it has been fixed in a JRun3.1 hotfix. I still don't see the fix though in JRun 4.0 ...
Problem with Servlets and RequestDispatcher.include()

JRun Hot Fixes Build 16777
Fixes the following bug that was causing me errors...
26529 - 3.1 Regression. Servlet using getRequestDispatcher with an unbounded array of URLs causes "response has been closed" in Jrun 3.1. ex: RequestDispatcher dispatcher =
req.getRequestDispatcher(urlstrings);
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use JSTL's <c:import> tag, which supports cross-context imports through the use of the 'context' attribute, then the behavior will be what you're looking for.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Thambi Rajah:
I tried to include a JSP page(Inner.jsp) from a Web application(examples)
into another JSP page(Outer.jsp) which is in a different Web application(demo).

I was posting to the original question.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!