Click to See Complete Forum and Search --> : Uploading files at server
saddysans
January 31st, 2003, 12:01 AM
I have to develop a website where user can upload their html page. This webpage i have to save on server. For every user i have to create a folder with the name of his userid. Now my problem is, to create a folder i must know the absolute path of my jsp page(which is not possible). How can i create a folder in the folder in which my jsp page exist.
thanx
saddysan
dlorde
January 31st, 2003, 07:35 AM
The ServletContext (available from the ServletConfig, which is implemented by GenericServlet and HttpServlet) has two methods, getRealPath(...) (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)) and getResourcePaths(...) (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#getResourcePaths(java.lang.String)), which might be useful - getRealPath(...) can give you the absolute path for a given virtual path or context path (relative to the document root).
You haven't said what the HTML pages in the user directories will be used for, but I would seriously question whether it's a good idea to put them in your web application JSP folder. After all, this is where you put files that you intend to make public on the web, and ISTM it makes sense to restrict access to a user's files to the user that created them, quite apart from the maintenance problem of having user files in the middle of your web application... How will you handle these files when you finish development and deploy your web application as a single .EAR?
I detest war, it ruins conversation...
saddysans
February 1st, 2003, 11:55 AM
Thanks dlorde,
I totally agree with you, that this sort of architecture(saving html files in the directory of jsp) is not a good idea. The html pages which users will upload will be used as their advertisments.
Thanx
saddysan
dlorde
February 2nd, 2003, 02:05 PM
OK, I guess adverts are probably less sensitive that some data...
However, I would still recommend storing them somewhere else so as to keep your application and the user's adverts separate. As I said, when you deploy your application as an EAR, the JSP direcory won't be available at runtime. In similar situations, I have stored the user data in a directory elsewhere on the server (or even on a different server) using a path or URL I read from a properties file. This allows you to dynamically change where you save the user data, or switch the user data in use to a different set, without stopping the application. Where I stored the data on a different server, I used a simple servlet on that server to save and to return the data on request. When you're using JSP, it's simple to write a custom tag to read data from a server directory or remote server - alternatively, you can use a servlet to retrieve the data before passing it to the JSP...
Preachers say, 'Do as I say, not as I do'...
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.