Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8228059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:20:27+00:00 2026-06-07T16:20:27+00:00

How can I hide files on my web server? I have a directory ‘

  • 0

How can I hide files on my web server? I have a directory ‘files‘ in which I am storing some pdf files. I don’t want to let the user access files by a URL like this:

www.example.com/files/1.pdf

Instead of this I want to map each file with an id in a DB and let the user access it like this:

 www.example.com/fileId=5569a

The user should not be able to access the files directory.

How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:20:28+00:00Added an answer on June 7, 2026 at 4:20 pm

    that is a pretty forward answer

    First of all you should deny access to the directory using the deployment descriptor (web.xml)

    <security-constraint>
       <display-name>excluded</display-name>
       <web-resource-collection>
          <web-resource-name>No Access</web-resource-name>
          <url-pattern>/files/*</url-pattern>
       </web-resource-collection>
       <web-resource-collection>
          <web-resource-name>No Access</web-resource-name>
          <url-pattern>/files/*</url-pattern>
          <http-method>DELETE</http-method>
          <http-method>PUT</http-method>
          <http-method>HEAD</http-method>
          <http-method>OPTIONS</http-method>
          <http-method>TRACE</http-method>
          <http-method>GET</http-method>
          <http-method>POST</http-method>
       </web-resource-collection>
       <auth-constraint />
       <user-data-constraint>
          <transport-guarantee>NONE</transport-guarantee>
       </user-data-constraint>
    </security-constraint>
    

    Now that your files are safe you have to implement a Servlet with url-mapping ‘/’ that will check to find the ‘fileId’ parameter in the request. If it finds it, the servlet will offer the file download to the user, else it will redirect the user to the homepage.

    For implementing a servlet please see post Call a servlet on click of hyperlink

    For implementing the file download please see my post Is there a common way to download all types of files in jsp?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created some PDF files programatically, which i am storing into the devices
I have a web page for which I made two css files, one for
Scenario: I place some files on Google web storage. And I want only paid
Today I got an issue, which says I should hide some files from the
how can hide particular button which is created from UIBarButtonItem in iphone ?
What is the simplest way I can hide a sensitive identifier, while providing some
I can't hide my div using some i.e. explode effect in jquery ui, It
How can I hide a field in a SharePoint alert? I have a custom
How can we hide (invisible) some CodeBehind lines (for example a class) from other
hoping some one can shed some light on my problem. Basicly I only want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.