> Hi people, I'm trying to build a counter in JSP that stores counter
> values in a property file. But I'm facing a problem, I can't open
[quoted text clipped - 5 lines]
> counter
> values) that property file.
A deployed web application (what JSP pages are a part of) cannot assume
there is a file system. In that regard, you'd have to use a database.
This is somewhat complex for just a counter. But if you are willing to
make demands on the server, you have another possibility:
If you are willing to sacrifice some security, you can let the server
allow the web application to write to its own webapp directory. IIRC,
Tomcat allows this by default, but check this with the docs to be certain.
If the server allows access to the directory of the web application, you
can get a directory to write to whose contents are also in the classpath:
<% String directoryName = config.getRealPath("/WEB-INF/classes"); %>
NOTE however, that this method can will return null if the path cannot be
translated (for example when you use a .war file). In that case, what you
are trying to do is not possible.
It is therefore preferable if you find that another solution is feasible.
For the current counter example this is doubtful, but if you wish to store
more information a database is the way to go.

Signature
Oscar Kind http://home.hccnet.nl/okind/
Software Developer for contact information, see website
PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
hernan rancati - 26 Feb 2005 04:36 GMT
Hi Oscar, thank you for your wise response:).
So, I can't rely on filesystem, what a life. I will go on the
database direction thatyou mentioned. But, do you know how struts
framework access it's xml files like struts-config.xml or the
ResourceBundle.properties? They access that files using
config.getRealPath()??
I'm a little confused. anyway, thanks..
Hernan Rancati.
Oscar kind <oscar@danwa.net> wrote in message
> A deployed web application (what JSP pages are a part of) cannot assume
> there is a file system. In that regard, you'd have to use a database.
[quoted text clipped - 18 lines]
> For the current counter example this is doubtful, but if you wish to store
> more information a database is the way to go.
Oscar kind - 26 Feb 2005 10:57 GMT
> So, I can't rely on filesystem, what a life. I will go on the
> database direction thatyou mentioned. But, do you know how struts
> framework access it's xml files like struts-config.xml or the
> ResourceBundle.properties? They access that files using
> config.getRealPath()??
Reading files is easier. You still cannot depend on a file system, but you
don't have to: there is the classpath. Every Class and every instance of
it is loaded by a ClassLoader, which gets its classes and resources
(read: files, sort of) from a classpath. All you know is that you can ask
it for classes and resources: You don't really know how it gets them (read
from a file, read from a .jar file, created on the spot, ...).
To get a resource from the classpath, you can use
Class#getResource(String) and Class#getResourceAsStream(String).
To get a file from the root of the web application, you can use
ServletContext#getResource(String) and
ServletContext#getResourceAsStream(String).

Signature
Oscar Kind http://home.hccnet.nl/okind/
Software Developer for contact information, see website
PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
hernan rancati - 26 Feb 2005 20:08 GMT
Oscar, I didn't know that there is ServletContext#getResourceAsStream(), still
doesn't work for my counter but is nice to know.
thanks!
Hernan Rancati (cesare)
> Reading files is easier. You still cannot depend on a file system, but you
> don't have to: there is the classpath. Every Class and every instance of
[quoted text clipped - 9 lines]
> ServletContext#getResource(String) and
> ServletContext#getResourceAsStream(String).
t