Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: jsp - file location

Reply
Thread Tools

Re: jsp - file location

 
 
Nikolaj
Guest
Posts: n/a
 
      07-04-2003
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" <(E-Mail Removed)> wrote in message news:<eIlJa.1812$(E-Mail Removed)>...
> In the web-inf directory.
>
> "Nikolaj" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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.

 
Reply With Quote
 
 
 
 
Andy Flowers
Guest
Posts: n/a
 
      07-04-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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" <(E-Mail Removed)> wrote in message

news:<eIlJa.1812$(E-Mail Removed)>...
> > In the web-inf directory.
> >
> > "Nikolaj" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Location, location, location =?Utf-8?B?VHJhY2V5?= Wireless Networking 2 02-17-2007 08:37 PM
Declaring a variable in one JSP file and accessing it in another JSP file anubhakhurana@gmail.com Java 8 10-11-2006 01:15 AM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
JSP to get the WAR file location jrefactors@hotmail.com Java 2 12-16-2004 08:17 PM
JSP to get the WAR file location jrefactors@hotmail.com Java 0 12-16-2004 08:04 PM



Advertisments