JSP file download

K

Kasper M. Nowak

Hello,

I need to know how to do the following:
User logs in, password is compared with database, then user can see a
list of files in "his" directory (which only he can have access to) and
download them. For every user there is a separate directory with
different files.
Login and all the rest ist done with JSP and working, my problem is I
just don'T have any idea how to solve the problem with the
directories/files and downloading them. I would really appreciate any
help like code samples, links, .. whatever

Thanks a lot in advance

Kasper M. Nowak
 
C

Chris Smith

Kasper said:
I need to know how to do the following:
User logs in, password is compared with database, then user can see a
list of files in "his" directory (which only he can have access to) and
download them. For every user there is a separate directory with
different files.
Login and all the rest ist done with JSP and working, my problem is I
just don'T have any idea how to solve the problem with the
directories/files and downloading them. I would really appreciate any
help like code samples, links, .. whatever

Are you already using a database? Do you have a record for each user
account in the database? Or do you prefer to use filesystem storage?
You'll need to be more specific about your design.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
K

Kasper M. Nowak

Chris said:
Are you already using a database? Do you have a record for each user
account in the database? Or do you prefer to use filesystem storage?
You'll need to be more specific about your design.
Well there is a user-database already, which stores usernames,
passwords,... for each user. But the files themselves should be stored
in the Filesystem.
 
W

Wendy S

Kasper M. Nowak said:
Well there is a user-database already, which stores usernames,
passwords,... for each user. But the files themselves should be stored
in the Filesystem.

Once the user logs in and you know his userid, can you construct the URL and
the path for the directory the file lives in?

Then you can get a list of the files (see java.io.File)? If so, you can
iterate through the list of files and tack on the known "first part" of the
URL.
 
W

Wendy S

Kasper M. Nowak said:
If I understand rightly what you mean, I'd have to allow acces to the
user-file directories with a http server, which is very insecure,
because you just have to type in the exact URL of a file into your
webbrowser to download it without any authorization, that's why I can't
use this solution...

Okay, then how about a Servlet that takes the userid/filename as parameters
and then streams the file back at the browser.

The URLs you present as the files to be downloaded are mapped to that
Servlet, it figures out which file, and sends it back.
 
C

Chris Smith

If I understand rightly what you mean, I'd have to allow acces to the
user-file directories with a http server, which is very insecure,
because you just have to type in the exact URL of a file into your
webbrowser to download it without any authorization, that's why I can't
use this solution...

Okay, so write a servlet to handle it. Use request.getPathInfo() to
retrieve the directory name. Perform your security validation before
returning the result.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top