• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

storing text files server side.

 
Micky Pat
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Micky Pat
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naseem, you are a total star...



Thank you very much
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic