3 messages in com.mysql.lists.javaRe: Servlet Local Path| From | Sent On | Attachments |
|---|---|---|
| Edilmar Alves | 09 Jun 2000 07:21 | |
| Tim Endres | 09 Jun 2000 10:02 | |
| Tom Myers | 09 Jun 2000 11:53 |
| Subject: | Re: Servlet Local Path![]() |
|---|---|
| From: | Tom Myers (tom....@postoffice.worldnet.att.net) |
| Date: | 06/09/2000 11:53:54 AM |
| List: | com.mysql.lists.java |
Hi,
Edilmar Alves <edil...@intersite.com.br> had said
My servlet app with Linux+Apache+JServ+JBuilder3+MySQL needs to open text files into a subdirectory from servlet dir.
Today, I use the "ugly" strategy: the code has explicitly all the PATH to access the file.
and Tim Endres wrote:
You can do this by using System.getResoure(), which will let you get the file from the JAR even (or any place on the CLASSPATH...
It's a bit off-topic, maybe, and Tim's solution will work fine, but you may prefer to use the actual servlet dir rather than the classpath; if I'm running a "DomSearch" servlet invoked as
http://localhost:8080/examples/DomSearch?a=b&c=d&soForth=soOn
and the initParameter "configFile" is "/servlets/data/dsStamps.xml", then getServletContext().getRealPath(getInitParameter("configFile"))
has the value, in this case, of
C:\jakarta-tomcat\webapps\examples\servlets\data\dsStamps.xml
because C:\jakarta-tomcat\webapps\examples is the starting directory, the "DocBase", for servlets running in the "examples" webapp. That's specifically Tomcat 3.1, but it works the same on JRun and I don't think you'll have any problem figuring it out elsewhere.
Tom Myers




