How to find the parent directory of a servlet?
Created Nov 26, 2002
Gerrit Goetsch try this..
to get the URL
java.net.URL url;
try {
url = new java.net.URL(new java.net.URL(req.getRequestURL ().toString()),"../");
} catch (java.net.MalformedURLException e) {
// catch the exception ....
}
or this to get the real path
String path = new java.io.File(getServletContext().getRealPath("")).getParent();
to get the URL
java.net.URL url;
try {
url = new java.net.URL(new java.net.URL(req.getRequestURL ().toString()),"../");
} catch (java.net.MalformedURLException e) {
// catch the exception ....
}
or this to get the real path
String path = new java.io.File(getServletContext().getRealPath("")).getParent();