aspose file tools*
The moose likes Servlets and the fly likes storing text files server side. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "storing text files server side." Watch "storing text files server side." New topic
Author

storing text files server side.

Micky Pat
Greenhorn

Joined: May 03, 2006
Posts: 18
Good morning,

I have the following problem: I have created in my desktop a small servlet which has the capability of storing and retrieving text files from a local directory. Say that this directory is specified as a context parameter in the DD, like:

<param-value>C:/.../webapps/MyServletProject/WEB-INF/userData/users.txt</param-value>

My question is: how can I deploy this server side? Is there a general way to retrieve where the project MyServletProject is located?

I know that I should work with databases instead, but I got stuck on this point, which looked straighforward to me at the very beginning....
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
In your case, as you are saving the url of the file by context param, so only thing you have to do is get the value (i.e., url). Once you get the url, a java.io.File instance can refer to the file.

Now the question is how to get the param-value. For that, you need to get an instance of ServletContext.

But this is less flexible. Everytime when your application move to some other location, then accordingly you have to update the context-param.

Calling ServletContext.getRealPath("RELATIVE_URI_OF_FILE") is better approach than yours.

getRealPath(java.lang.String path)


Naseem
[ August 26, 2006: Message edited by: Naseem Khan ]

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Micky Pat
Greenhorn

Joined: May 03, 2006
Posts: 18
Naseem, you are a total star...



Thank you very much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: storing text files server side.