Juuno
asked on
Get filepath in web application
Hi,
How can I get the path of my web application?
For example, i'm working on eclipse and the name of my web application is Test which path is "C:\Documents and Settings\user\workspace\Te st". And I have my xml files in "C:\Documents and Settings\user\workspace\Te st\WebCont ent\WEB-IN f\Classes\ Resources\ ". How I can do to get that path from my javabean which i can't extend it to the HttpServlet class.
How can I get the path of my web application?
For example, i'm working on eclipse and the name of my web application is Test which path is "C:\Documents and Settings\user\workspace\Te
ASKER
I've already tried it.
I can get the file path if my program is stand alone.
For web application, I just got C:\Eclipse, since user.dir contains the current working directory (ie. where the vm was run from).
I can get the file path if my program is stand alone.
For web application, I just got C:\Eclipse, since user.dir contains the current working directory (ie. where the vm was run from).
But you want the location of the xml?
ASKER
It is like I want to retrieve xml from my java bean, so, I want to get that path to my java bean. In my standard program. I used this:
static String curDir = System.getProperty("user.d ir");
static String resources = ("\\WebContent\\WEB-INF\\c lasses\\re sources");
and I give the path for my xml file like this
File file = new File(curDir + resources + "myxml.xml") and it works.
But for my web application, System.getProperty("user.d ir") only returns C:\Eclipse where VM runs.
So, I want to know how to get file path in web application.
static String curDir = System.getProperty("user.d
static String resources = ("\\WebContent\\WEB-INF\\c
and I give the path for my xml file like this
File file = new File(curDir + resources + "myxml.xml") and it works.
But for my web application, System.getProperty("user.d
So, I want to know how to get file path in web application.
ASKER
Thanks.
But my JavaBean program can't extend to Servletcontext.
But my JavaBean program can't extend to Servletcontext.
you'll need to pass it a context (or request) to determine the path
>But my JavaBean program can't extend to Servletcontext.
You are right. But you could create a load-on-startup servlet. In its init method you could set the ServletContext into a field of a static utility class. Your javabean could access that.
You are right. But you could create a load-on-startup servlet. In its init method you could set the ServletContext into a field of a static utility class. Your javabean could access that.
ASKER
Thanks.
Can you explain me a bit more about load-on-startup servlet. How can I do this?
Can you explain me a bit more about load-on-startup servlet. How can I do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window