[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Design .jsp (or other) to dynamically create page based on items found in directory

Posted on 2005-04-05
4
Medium Priority
?
176 Views
Last Modified: 2010-04-01
Hey Gang,

I am a Solaris admin, but not a web designer (have had a little experience...very little.)

We are running Apache 2.0.35 on Solaris 5.8.

I would like to create a page (.jsp, or whatever) that dynamically looks at the list of items within the “../htdocs/subdir” directory within Apache, and creates a page on the fly with those items as links to that file/dir.

The reason being is, we want to be able to have scripts copy directories full of “txt” documents into “../htdocs/subdir” without us having to hand re-write the web page with the links.

I.E...
# ls ../apache2/htdocs/servers
serv1 (dir)
myserv (dir)
document.txt
differentDoc.html

Webpage****
Hi!  Welcome to the admin webpage!  Click any of the links below...
serv1
myserv
document.txt
differentDoc.html

...and clicking differentDoc.html brings up that page, clicking document.txt brings up that doc, and clicking on the link for serv1 or myserv just takes you into that dir (the subdir does not need formatting, per se’-as it will just be .txt docs the person can click on.)

A million thanks
Mike
0
Comment
Question by:Mike R.
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
bloodredsun earned 2000 total points
ID: 13715342
This will output a clickable list of all your files and directories

ls.jsp
-------
<html>
<head><title>list files and directories</title>
</head>
<body>
<%
      String currentLocation = getServletContext().getRealPath("/") ;
      String[] arDirs = new java.io.File(currentLocation).list();
      java.util.Arrays.sort(arDirs) ;
      for( int ii=0 ; ii<arDirs.length ; ii++){
            out.println( "<a href='"+arDirs[ii]+"'>"+arDirs[ii]+"</a><br>") ;

      }
%>
</body>
</html>
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13715396
This is a neater version that also returns whether the file is a "file" or a "directory". You should note that this jsp works for the current webapp that it is in (it finds that from the call getServletContext().getRealPath("/") ). If you wanted to hard code the apache htdocs directory, then just replace line with the correct one.

new version of ls.jsp
--------------------------
<%@ page import="java.io.*, java.util.*" %>
<html>
<head><title>list files and directories</title>
</head>
<body>
<%
      String currentLocation = getServletContext().getRealPath("/") ;
      String[] arDirs = new File(currentLocation).list();
      Arrays.sort(arDirs) ;
      for( int ii=0 ; ii<arDirs.length ; ii++){
            File file = new File(currentLocation + arDirs[ii]) ;
            String type = file.isFile() ? " &lt;file&gt;" : "  &lt;dir&gt;";
            out.println( "<a href='"+arDirs[ii]+"'>"+ arDirs[ii] + type +"</a><br>") ;
      }
%>
</body>
</html>
0
 
LVL 3

Author Comment

by:Mike R.
ID: 14157406
Hey Gang,

Sorry about all the delays.  As it turns out, I am being forced to re-allocate this server to a different function...so I am going to have to start the process over.

I am going to assign points since I think you gave me what I need to know...I just need to test it.  I will resubmit another question if i run into more snags!

Thanks for the help and the patience!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If anyone asked you to network diagram of the internet, it was drawn in the form of a fluffy cloud which further became known as cloud computing. Popularly cloud computing is defined as workloads that run over the internet in a commercial provider’s…
Most folks would know the basics of how Dropbox works, so that’s not the purpose of this article. Security is what it’s all about, so here I’ll share how I choose to secure my Dropbox Account and the Data it contains.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question