..
> ..
>
>>Now, how may I know what exactly is "http://some.host.net:port/myApp/"
>>from whitin a JSP or a servlet?
>
> <http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#
getRealPath(java.lang.String)>
That would give you only the RealPath relative to the local file system.
(On my local server, it would return "/opt/tomcat55/webapps/myApp/xxx" )
The original question cannot really be answered in a global context. For
instance, the same resource may be available under several variants of
the URL. e.g. A certain page that may be accessible as
"http://127.0.0.1:8080/myApp/index.jsp" from my local machine would only
be accessible with a different hostname/IP when the same is accessed
from another machine on the internet.
This information therefore would be relevant only in the context of a
particular HTTP request, and one can obtain it using :
request.getRequestURL();
BK
ElectricHappiness.com - 30 Aug 2006 05:49 GMT
I actually just tackled a similar problem. But my hosting company
would not allow me to write to my own domain, I had to write to a
generally accessible temp folder.
Just copy and paste this code into a servlet/JSP page and run it. It
should reveal which method you should use.
where...
F = first letter of login name
S = second letter of login name
T = third letter of login name
try{
x = new File("/home/content/F/S/T/FSTloginName/html/temp/1.txt");
filUploadedFile = new File("/tmp/1.txt");
filUploadedFile.createNewFile();
out.println("<br>");
}catch(Exception e){
e.getLocalizedMessage();
out.println("<br><br>");
out.println(e.getLocalizedMessage());
out.println("<br>" );
}
try{
x = new File(request.getContextPath() + "./" + "f.txt");
x.createNewFile();
out.println("good " + x.getAbsolutePath());
out.println(" x.getAbsolutePath()<br>");
}catch(Exception e){
out.println("<br><br>");
out.println("BAD 1-> request.getContextPath()./<br>");
out.println("<br>" + request.getContextPath());
}
try{
x = new File(request.getContextPath() + "/" + "e.txt");
x.createNewFile();
out.println("good " + request.getContextPath() + "<br>");
out.println(" request.getContextPath(/)<br>");
}catch(Exception e){
out.println("<br><br>");
out.println("BAD 2-> request.getContextPath()/");
out.println("<br>" + request.getContextPath());
}
out.println("<br><br>round 2<br><br>");
try{
x = new File(".", "d.txt");
out.println("good " + x.getAbsolutePath());
out.println(" x.getAbsolutePath()<br>" );
x.createNewFile();
}catch(Exception e){
out.println("<br><br>");
out.println("BAD -> new File(.)");
out.println("<br>" );
}
try{
x = new File(request.getContextPath(), "c.txt");
x.createNewFile();
out.println("good " + x.getAbsolutePath());
out.println(" x.getAbsolutePath()<br>");
}catch(Exception e){
out.println("<br><br>");
out.println("BAD 1-> request.getContextPath()./<br>");
out.println("<br>" + request.getContextPath());
}
try{
x = new File(request.getContextPath(),"b.txt");
x.createNewFile();
out.println("good " + request.getContextPath() + "<br>");
out.println(" request.getContextPath(/)<br>");
}catch(Exception e){
out.println("<br><br>");
out.println("BAD 2-> request.getContextPath()/");
out.println("<br>" + request.getContextPath());
}
good luck!
<a href="www.electricHappiness.com">_</a>
> > ..
> >
[quoted text clipped - 19 lines]
>
> BK