Use the API.
The ServletContext class is what you want.
i.e. A call to xxx.getRealPath("WEB-INF"); in your servlet will return the
full operating system path to the WEB-INF directory in a J2EE application.
There are also other useful methods in this calls, such as getResource(...),
that you may want to investigate as well.
So you can store the file somewhere under the web app and get the OS path in
a machie independent way.
For example, a new textfiles directory under web-inf can be accessed via
xxx.getRealPath("WEB-INF/textfiles") or really do take a look at
getResource(..) and it's usage patterns.
"Victoria" <> wrote in message
news: om...
> I am able to run the servlet. However, the servlet has to read a file
> during the process, but I don't know what is the path should I place
> the file for the servlet to read. I can do it by using absolute path,
> but I think it is better to use relative path if I give the servlet
> for others to deploy.
>
> Maybe I give provide more detail......
> I just want the servlet to read a file called "test.txt", but I don't
> know what is the current directory,
> ie, where should I place the file in order to let the servlet to find
> the file without giving it the absolute path.
>
> Thanks!
> Tsz Yan
>
> "Andy Flowers" <> wrote in message
news:<luXOa.7352$>...
> > How are you attempting to load the file ? Can you post a snippet of code
?
> >
> > Also what errors are you receiving ?
> >
> > Also where is the servlet that you are using ?
> >
> > "Victoria" <> wrote in message
> > news: om...
> > > Hi,
> > >
> > > I've installed tomcat in my server, and I have written a servlet
> > > programme. In my programme, I will load a background file ( a svg
> > > file),
> > > but I don't know where I should place the file so that it can be
> > > loaded.
> > >
> > > I have created a folder called test(in the path C:\Program
> > > Files\Apache Group\Tomcat 4.1\webapps )and inside the test, I've
> > > created a folder call
> > > images and then place all the svg file in there, but I discover that
> > > they
> > > can't be loaded in my servlet.
> > >
> > > Can anyone tell me how can I fix this problem?
> > >
> > > Thanks a lot!
> > > Victoria
|