tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rashmi Rubdi" <>
Subject Re: Making a directory visible to tomcat
Date Sun, 03 Jun 2007 03:19:36 GMT
On 5/29/07, Peter Dawn <> wrote:
> guys,
> i am using tomcat 5.0. now i have created a file on my server at
> C:\data\packet.xml. when somebody accesses my web app remotely, i want
> the user to type in http://ipaddress:8080/packet.xml to be able to
> access this file.

One way to access the XML file at http://ipaddress:8080/packet.xml is
to write either a Filter or a Servlet, and specify /packet.xml as the
URL mapping for this Filter or Servlet in web.xml

And inside the Filter or Servlet, you would use Java I/O to access a
file that is outside the web application's context (in your case root

For example:

package somepackage;

import javax.servlet.*;

public class ShowPacketXMLFilter implements Filter {

    public void init(FilterConfig filterConfig) throws ServletException {


    public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse, FilterChain filterChain) throws
IOException, ServletException {


        PrintWriter out = servletResponse.getWriter();

        BufferedReader br = new BufferedReader(new

        String line;

        while ((line = br.readLine()) != null) {



    public void destroy() {



            This filter reads packet.xml from disk
            and displays it's content at /packet.xml


> can somebody please tell me how i can make a directory outside the
> installation folder visible to tomcat.

With Java I/O API you will be able to access any file , even if it is
outside the web application's context.

I don't know if there's a way to access any file outside the web app's
context using Servlet API , others may know.

> thanks


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message