• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:include and request dispatcher

 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose two files, a.jsp and b.jsp:
code for a.jsp:
<html>
<head><title>a.jsp</title></head>
<body>
<br>this is a's content...<br>
<br>included code:<br>
(1)
</body>
</html>

code for b.jsp:
<%@page language='java'%>
<br>this is b's content...<br>

%%%%%%%%%%%%%
if we replace (1) with <jsp:include page='b.jsp'/> or <jsp:include page='b.jsp' flush='true'/>
we are going to have the following will appear in the browser:

this is a's content...
included code:
this is b's content...

but if we replace (1) with:<%request.getRequestDispatcher("b.jsp").include(request,response);%>
the following will be printed:

this is b's content...
this is a's content...
included code:
Could someone clarify this...
Thanks in advance
 
Paul Yen
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Leandro,
If you use dispatcher, it will forward to the b.jsp page first then include the a.jsp page. Therefore the result is different from doing <jsp:include>.

Paul
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic