File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Including files in servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Including files in servlets" Watch "Including files in servlets" New topic

Including files in servlets

Carlin Jones

Joined: Apr 06, 2004
Posts: 3
Hey all. I'm trying to setup my web app so that I can store some design elements, like the headers and footers, in seperate files that I can change without needing to recompile my sevlets. The way I have it setup right now is I'm running tomcat through apache so is you went to for example http://localhost/ it would be handled by apache but http://localhost/forum/ is handled by tomcat. What I want to do is include a file from the servlet (in /forum/) that is located in the root apache directory. If thats not possible, is there another way of doing it or will I have to manually open the files and print them out inside the servlet?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63862

Perhaps you should consider forwarding from your servlet to a JSP for presentation? The hybrid servlet/JSP approach solves most problems you might encounter.

[Asking smart questions] [About Bear] [Books by Bear]
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it
Thanks! and welcome to the JavaRanch!

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Carlin Jones

Joined: Apr 06, 2004
Posts: 3
Alright. After looking at jsp forwarding for a bit it does seem like its what I should do. But I can't get it to work.
Here is what I have now:

All it does is display the code that comes from the servlet (which is what I would expect it to do since its forwarding). How do I print stuff in the jsp and then include the servlet output?
Whoops. Sorry about the name thing.
[ April 06, 2004: Message edited by: Carlin Jones ]
Carlin Jones

Joined: Apr 06, 2004
Posts: 3
Nevermind I think I figured it out.
I agree. Here's the link:
subject: Including files in servlets
It's not a secret anymore!