ModdyFire
ModdyFire

Reputation: 736

How to browse files using Tomcat

I'm trying to use Tomcat in order to access files on the server machine. I'm behind firewall so I don't care about security. Tomcat is already installed on that machine so I thought of using it. I read tomcat documentation, and also How can I list all the files in folder on tomcat?, and figured that I need to use the default servlet. I added:

<servlet>
    <servlet-name>default</servlet-name>
    <servlet-class>
      org.apache.catalina.servlets.DefaultServlet
    </servlet-class>
    <init-param>
        <param-name>debug</param-name>
        <param-value>0</param-value>
    </init-param>
    <init-param>
        <param-name>listings</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
... 
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

But I don't understand how I access the files from now - I thought that if I go to http:/machine:port/ I will get a listing, but I only got Tomcat's welcome page. I also tried http:/machine:port/C, but got 404.

I tried also to change the url-pattern to "/files", but still http:/machine:port/files gives me 404.

What am I doing wrong?

Upvotes: 1

Views: 2815

Answers (1)

Selva
Selva

Reputation: 1670

In order to access your system files from browser using tomcat,you have to create context path for the system files in tomcat server.xml like below.

<Context path="/my_img" docBase="C:/images" reloadable="true" />

Now you can see the files in your browser.By typing the below url.

http://localhost:8080/my_img/1.jpg like that

Upvotes: 1

Related Questions