• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible to include a file from a Servlet ?

 
Francesco Marchioni
author
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm using Tomcat 5.0.16 to develop my servlets.
I can see that including pages from servlets is not done
in the same page but rather is forwarded in another page.

The code is quite simple:
<i>
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");

getServletContext().
getRequestDispatcher("/snoop.jsp").
include(request,response);
}
</i>

This servlet displays the page "snoop.jsp" in another
page, but I'd like just to have at the bottom of the
page. Is it possible to do it?
Thanks a lot
Francesco
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By default the included page is displayed at the bottom of the page where you included it.Post the full code of servlet.
 
Francesco Marchioni
author
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
thanks for your answer.
Well, full code of the Servlet is just in those few lines in the doGet() method.
Nothing else.
Now if I think over it, it should be allowed to include a web page
from a Servlet in the same web page, as the response has been already
committed. (But so why they added the method "include" in a Servlet ?)Anyway I tested this on Tomcat 5.0.16. I'll try to have
a run on another Application Server and see it.
regards
Francesco
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have included a jsp in a servlet its working fine. Its get included at the bottom of the page where i have included it. I have used tomcat. Its working fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic