In your JSP use the API.
The ServletContext class, surfaced as the application pre-defined JSP
variable, is what you want.
A call to application.getRealPath("WEB-INF"); in your JSP 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.
The reason the simple FileWriter test you have done ends up in the directory
you specified is that this is where the JVM root is and this is the root
where the JVM will look for files with no qualifiers. Have a look at the
Java file APIs for descriptions of this.
"Nikolaj" <> wrote in message
news: om...
> But how do I access the files from my java-code if they are located in
> the web-inf dir. I have tried to have a jsp page save a file using a
> simple FileWriter:
> FileWriter fw = new FileWriter(new File("testFile"));
> fw.write("hello");
>
> The file ends up in a directory called Tomcat located in the directory
> of my web-application. (I'm developing in JBuilder). This doesn't seem
> very consistent, and how would I make this work on other servers if
> the web-application should be able to be deployed anywhere..
> How do I find the web-inf directory when I don't know the absolute
> path?
>
> Should I use URLs instead of files and paths.
>
> Hope someone can help me. Thanks.
>
> Nikolaj
>
>
>
> "Andy Flowers" <> wrote in message
news:<eIlJa.1812$>...
> > In the web-inf directory.
> >
> > "Nikolaj" <> wrote in message
> > news: om...
> > > I am developing an internet site based on jsp.
> > > The content of the site is a number of articles, which exist as plain
> > > unformatted text.
> > > I want the "front page" of the site to contain the headline of each
> > > article, and the first 15 words followed by "..."
> > > This should be done by automatically generating the html using java.
> > > The java-code should read the textfile and dynamically generate the
> > > front page, based on the articles currently available.
> > >
> > > Further more each hedline should be a link to the corresponding
> > > article, which should be a html page generated automatically from the
> > > text file containing the article.
> > >
> > > And now the question:
> > > Where should I locate the text files, which contains the unformatted
> > > articles. I do not want the text files to be accessible from a
> > > browser. Only the formatted versions of the articles should be
> > > accessible.
> > >
> > > I know that web applications have a directory which is used for
> > > storing temporary files, but it doesn't seem like a good solution to
> > > use this directory, since the files are not to be considered
> > > temporary.
> > >
> > > Hope you can help me. Thanks.
|