Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to prevent to see the directory structure in the browser?

 
Alam Vin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I type in http://localhost:8080/examples/jsp/myjsp/
on the browser and if "myjsp" directory contains subfolders and files, it's shown on the browser. How do we prevent them not to appear on the browser? Are there any settings on web.xml file?
Does it vary for different App servers?
Thanks in advance.
 
Rehan Malik
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some of the web browsers have settings which do not allow users to see the folders in a directory if there is no index file.
One quick and fast solution (if you don't have access to the web browser directly), is to throw in index.jsp (if it's JSP pages) or index.html documents into those folders (Blank pages of course) and it should take care of this.
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or turn off the DIR's read attribute (r) for group and others and leave execute (x).
Then you will get "FORBIDDEN" instead.
 
Alam Vin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I turned off the Read Attribute by right clicking on the folder and setting the attributes in the properties. But still I am able to see the directory structure. Am I missing something somewhere?
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you dont get to the solution using server configuration files, then you can create an empty file named index.html (or index.htm or start.htm, depending on your server settings) and put it in the directory where you want to prevent listings. you could also write some message in this file like "your not allowed to list the content of this directory".
in apache there is a entry in httpd.conf to prevent directory listings, perhaps there is also one on apache.

karl
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic