Restrict user to directly call an excel file by typing URL in browser address

Discussion in 'Java' started by jonesy, Oct 26, 2006.

  1. jonesy

    jonesy Guest

    Hi,

    I have a java servlet which on authentication redirects an Excel file.
    But I found the URL of the Excel file can be directly pasted in the
    browser address bar and then also the file can be directly downloaded
    without authentication.

    eg. I would like to restrict user from directly downloading the Excel
    file by entering the URL www.mysite.com/my/download/data.xls in IE
    address bar.

    The code below is what I am currently playing trial-and-error with. I
    would really appreciate any suggestions of whether I'm on the right
    track or not. I have a feeling I need to use DataOutputStream
    somewhere, but I'm really not sure.

    Any code, directions, help or suggestions would be great! Thanks :)


    Code:

    DataInputStream dis = null;

    byte[] buffer = new byte[0];

    try
    {
    File f = new
    File("./myserver/website_files/otherfiles/excelFile.xls");

    if (f.length() == 0)
    {
    //error handling
    }

    if (f.list() != null)
    {
    //error handling
    }

    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    dis = new DataInputStream(bis);

    dis.readFully(buffer);
    }
    catch (IOException e)
    {
    //error handling
    }
    finally
    {
    // if the file opened okay, make sure we close it
    if (dis != null)
    {
    try
    {
    dis.close();
    }
    catch (IOException ioe)
    {
    }
    }
    }
    jonesy, Oct 26, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. swbaz
    Replies:
    2
    Views:
    630
    Jordan Marton
    Aug 13, 2003
  2. Jaydeep
    Replies:
    3
    Views:
    1,046
    vedcyrus
    Jun 30, 2006
  3. vips
    Replies:
    4
    Views:
    457
    darrel
    Mar 31, 2005
  4. Replies:
    7
    Views:
    1,647
    Shunya
    Mar 1, 2006
  5. JimLad
    Replies:
    0
    Views:
    497
    JimLad
    Jan 26, 2010
Loading...

Share This Page