File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Is it possible to include a file from a Servlet ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Is it possible to include a file from a Servlet ?" Watch "Is it possible to include a file from a Servlet ?" New topic
Author

Is it possible to include a file from a Servlet ?

Francesco Marchioni
author
Ranch Hand

Joined: Sep 22, 2003
Posts: 190
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


WildFly 8 Administration Book - JBoss Tutorials
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
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

Joined: Sep 22, 2003
Posts: 190
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

Joined: Mar 18, 2004
Posts: 572
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Is it possible to include a file from a Servlet ?