File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How do I download files? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How do I download files?" Watch "How do I download files?" New topic
Author

How do I download files?

Sheldon Plankton
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
Hi,
I want to create a web application that will allow user's to download
files from my server.
I have this JSP and Java Bean ...

Here's a example of the HTML source this produces ...

When I access my JSP and click on one of the .txt links I get a 404 error?
The files do exist and permission on them are wide open. I have been making
symbolic links to the USER002 directory all over the place.
SUNWappserver/domains/domain1/applications/j2ee-modules/MyDownLoader
bash-2.03$ ls -l
total 6
lrwxrwxrwx 1 plank chumb 25 Mar 15 14:03 USER002 -> ../../../config/USER002
drwxr-xr-x 3 plank chumb 512 Mar 15 14:01 WEB-INF
-rw-r--r-- 1 plank chumb 409 Mar 15 14:01 index.jsp
bash-2.03$ cat USER002/.htaccess
AddType application/octet-stream .inq

Is there something wrong with my <a href=> tags? Is there a problem using symbolic links? Is there something other than just having a .htaccess file in my USER002 directory?
Please help!
[ March 15, 2004: Message edited by: Sheldon Plankton ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61209
    
  66

You've made the href's relative to the serlvet. Make them context relative (leading /), or provide a base tag in the JSP to force the relative base.
[ March 15, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sheldon Plankton
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
Thanks Bear,
I made that change ... redeployed ... restarted my server ... added a symbolic link in my docroot dir to USER002 but still I get 404
The <a href> tags now look like this ...
<a href='/USER002/20040103120005.txt'>20040103120005.txt</a>
What else should I check?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61209
    
  66

Is USER002 located at the root of your web app? You simply need to create a URL that will address the location of the files. If the folder is located outside the range of the web server, no URL on earth will serve it up. (Though it's easy to write a servlet that can).
So, where are you storing the files?
Sheldon Plankton
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
Hi Bear,
bash-2.03$ pwd
/usr/local/home/Plank/SUNWappserver/domains/domain1
bash-2.03$ find . -name 'USER002'
./config/USER002
./docroot/USER002
./config/USER002 is an actual directory
./docroot/USER002 is a symbolic link to /usr/local/home/Plank/SUNWappserver/domains/domain1/config/USER002
I beginning to think it is a problem with the symbolic link and that's going to be a problem for me
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I download files?