View Full Version : To view the list of directories using HTML
Sowmya
02-15-2017, 11:43 AM
Hi,
I want to list the directories available on some location(say some path) on linux box using HTML. Can someone please help writing the index.html.
So I can access over the web.
Tried using .htaccess, and could not get any results. is something do we need to enable from apache server. please let us know earliest. Thanks!!!
Thanks,
Sowmya
jscheuer1
02-15-2017, 01:45 PM
Actually it's the absence of an index page that lets you see the directory listing. And yes, it has to be allowed in the server configuration, though that should be able to be modified for any given folder or folders using .htaccess. Most servers allow it by default though.
If you have a page named home.*, index.*, or default.* (the * being like html, htm, php, asp, or some other valid presentational extension) in the folder, by default the browser will see that. If not, it should see the directory listing.
Sowmya
02-16-2017, 05:55 AM
Yes. Thanks John. By default browser is referring the index.html and listing the directories. I have coded manually in index.html to show the directories. Someone help writing the HTML code which automatically lists the directories available in the respective location.
jscheuer1
02-16-2017, 06:28 AM
HTML isn't that powerful. As I say, as long as there's no index or other default page in the folder, simply navigating to the folder will list the entries. Like if you have a folder called demos on whateverdomain.com that has no default page in it and you go in your browser to:
http://www.whateverdomain.com/demos
most servers will show the directory listing. Now, whether the server is configured to do that or not, no HTML page can show the directory, at least not by itself. If the server has PHP, a .php page could. And an HTML page that fetches (via javascript and AJAX) the contents of a PHP script could. Even an HTML page could do it directly via PHP if the server parses it as PHP (must be set in the server's configuration or via .htaccess). This can also be done in asp or ASP.NET and other server side languages. But using only HTML, it cannot be done.
Sowmya
02-16-2017, 11:42 AM
Thank you John.
It worked by following as below,
Let's make a simple application for an online document share, which lets us browse it's /files folder.
First create a new application folder in your webapps folder called Browser
In the new Browser folder, create two folders: WEB-INF and files
The files folder will be our browseable folder. Create some other subfolders under files (eg: photos and code), and add a few example files such as some photos or source code, so that we have something to browse.
Copy the following into /Browser/WEB-INF/web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Browser</display-name>
<description>File Browsing Application for the Document Share</description>
<!-- Enable directory listings by overriding the server default web.xml -->
<!-- definition for the default servlet -->
<servlet>
<servlet-name>DefaultServletOverride</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Add a mapping for our new default servlet -->
<servlet-mapping>
<servlet-name>DefaultServletOverride</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
jscheuer1
02-16-2017, 04:15 PM
Definitely not HTML. Glad you figured this out. Does that all go on the server? When you view that in a browser*, does the address in the address bar end in .htm or .html? or is it just files or files/ at the end of the address?
This was for viewing in the browser, right?
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.