• Post Reply Bookmark Topic Watch Topic
  • New Topic

Application to serve files.  RSS feed

 
Susan Smith
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application where this application serves ZIP files to our client.

But before they get passed through the ZIP files, they need to pass through a JSP (to count how many times they are coming, other miscellaneous things, etc)

=== I understand that servlet might be a better option, but currently it is a JSP and I can't change it. The JSP must stay, at least for a while. ===

How do I build it so that the file is protected, then it will be accessible only after the clients passed through the JSP?
Does anyone ever experience the same challenge?

Thanks in advance for the help.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36453
459
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Susan,
Where are the zip files located that you are trying to protect?
 
Srikanth Nutigattu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends where do you place your zip files. If they are placed in the application root or subfolders of it, then any one can access the same without using the JSP if they know the URL to your file.

If you really want to protect your files then place them in the private section, create any subfolder under WEB-INF and access those files using JSP/JAVA.

try to use ServletContext's getResourceAsStream() method to access the -file. I haven't used that though but will check and let you know if it worked.

Cheers!!
[ December 02, 2008: Message edited by: Srikanth Nutigattu ]
 
Susan Smith
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne, Srinkath.

Thanks for your reply.

The zip files themselves are not well-protected currently.

--------------------------------------------------------
If you really want to protect your files then place them in the private section, create any subfolder under WEB-INF and access those files using JSP/JAVA.
--------------------------------------------------------
Srikanth, this is very interesting idea.

Just to be sure:
Your suggestion for this is to generate the files in that directory.
And then the JSP will try accessing it using Class.getResourceAsStream();

Is it redirection?

Can JSP access whatever under WEB-INF?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36453
459
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Susan Smith:
Can JSP access whatever under WEB-INF?

Yes. The JSP can access any files. It's the user (direct access) that it is protected from.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Susan Smith:
... The JSP must stay, at least for a while. === ...


Once this requirement is dropped, you might want to consider either streaming the files from a directory that is not accessible to the web (like WEB-INF) using a servlet.
See:
http://faq.javaranch.com/java/CodeBarnSimpleStream
For an example app that does just this.

The second option mentioned would be to put all the zip files in a directory that is accessible to the web and to create a ServletFilter that restricts access to that directory to people who meet your criteria (in a particular role, have a particular object bound to their session, etc...).
[ November 27, 2008: Message edited by: Ben Souther ]
 
Susan Smith
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. The JSP can access any files. It's the user (direct access) that it is protected from.

Thanks, Jeanne. I'll give it a try.

Ben, thank you. I will consider this for near future soon.
 
Susan Smith
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, I have a back-end java program that generate/ update this file from time to time. I need to test whether this java program can put the file into the WEB-INF directory or not.

This java program program is under the same web application directory with the JSP.

Thanks.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Susan Smith:
By the way, I have a back-end java program that generate/ update this file from time to time. I need to test whether this java program can put the file into the WEB-INF directory or not.


Putting the files in the WEB-INF directory wont be a problem, but if they are updated periodically, then just make sure you dont run into concurrency problems.
 
Srikanth Nutigattu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one solution to solve the concurrency problem would be to temperorily rename the file while it is being modified. or make a copy then delete the old one.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!