thx 4 ur help, this it is what I wanted.
But there is also another Question. I have a ".exe-file" that I want to start out of the servlet. Of course with some paramteters and one of my data-files as one of the parameters. Is that possible? And how do I do that?
If that works and the .exe-file is accessing my data-file and another instance of the servlet does the same the tomcat can be crash or the servlet or so. How do I handle that?
Patrick
Shapira, Yoav wrote:
Howdy,
How do I connect to a Data-File above the WEB-INF-Folder from aservlet????
For example my class is placed inData files belonging to or referenced by your webapp should be under
$CATALINA_HOME/webapps/ROOT/WEB-INF/classes/myApp/server/servlet.class
and my data-files are placed in $CATALINA_HOME/webapps/data/data.dat or
so. Is this possible or does anybody know a better way to place my
data-files? And how do I connect to them?
your webapp's structure (or within your webapps .war file). So if your
app is in the ROOT context, your data files should be in
$CATALINA_HOME/webapps/ROOT/data/data.dat.
Then, from your servlets, you could do:
InputStream is =
getServletContext().getResourceAsStream("/data/data.dat");
(and do whatever you need with the input stream, e.g. read it)
or
URL fileUrl = getServletContext().getResource("/data/data.dat");
To just get the URL for the file. Don't assume this is a file:// or an
http:// URL. It may be a jndi:/localhost/... type of URL as well.
You could also use String filePath = getServletContext().getRealPath("/data/data.dat");
approach, but that won't work if you're deploying out of a .war file.
Finally, if for some reason you cannot place your data files under your
own context, you can set a data file directory as a context parameter in
your web.xml. For example:
<context-param>
<param-name>dataFileDirectory</param-name>
<param-value>/home/myname/mydatafiles</param-value>
</context-param>
Then in your servlets, you could do:
String dataFileDirectory =
getServletContext().getInitParameter("dataFileDirectory");
String filePath = dataFileDirectory + File.separator + "data.dat";
And go from there.
I hope you find this helpful,
Yoav Shapira
Millennium ChemInformatics
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
