Re: Relative paths in servlets?

2003-01-06 Thread Øyvind Hvamstad
On Mon, 2003-01-06 at 16:31, Jacob Kjome wrote:

> Assuming the .war file is in CATALINA_HOME/webapps
> 
> 
> Make sure to stop tomcat before you put the .war file into webapps.  Add 
> the above to your server.xml or a context configuration file (like 
> admin.xml or manager.xml are set up).  Then put the .war file into 
> webapps.  Now start Tomcat.  Then, try to access a servlet which uses 
> getRealPath("/").  Check the value.  I guarantee it is null.
> 


I am using the ant installTask, I was somehow confused to believe that
it used .war, but that was a mistake. No need to be agrevated.


  


 war="file://${build.home}"/>

  


> Jake

Thanks

Øyvind


--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: Relative paths in servlets?

2003-01-06 Thread Jacob Kjome

You are confusing the WAR structure with the actual .war archive.  The .war 
archive is a .jar format archive.  I challenge you to try to use File IO to 
access a file inside a .jar or .war archive.  If you can do it, please let 
us all know because you will have broken new ground in Java :-)

Remember that Tomcat auto-expands .war files to a directory structure and 
then deploys the directory structure.  Also, you mention that your 
contextPath points to the "build" *directory*.  That is, obviously, not a 
.war file archive, but a directory structure which will, quite obviously, 
work to get a real path using File IO.  The only way to test serving out of 
a .war archive in Tomcat is to define a  element with the docBase 
pointing to a .war archive.  For instance...

Assuming the .war file is in CATALINA_HOME/webapps


Make sure to stop tomcat before you put the .war file into webapps.  Add 
the above to your server.xml or a context configuration file (like 
admin.xml or manager.xml are set up).  Then put the .war file into 
webapps.  Now start Tomcat.  Then, try to access a servlet which uses 
getRealPath("/").  Check the value.  I guarantee it is null.

Jake

At 03:23 PM 1/6/2003 +0100, you wrote:
On Mon, 2003-01-06 at 15:22, Jacob Kjome wrote:

> Check is that is null before using it as it *will* be null if you serve
> your app directly from a .war file rather than from a directory on the 
file
> system.

Odd, I do serve mine from a .war file, however the contextPath is not
null, but points to the build directory. This is probably not true if
the war is buildt elsewhere than on the local host.

> Jake

Thanks

Øyvind


--
To unsubscribe, e-mail:   
For additional commands, e-mail: 


Re: Relative paths in servlets?

2003-01-06 Thread Øyvind Hvamstad
On Mon, 2003-01-06 at 15:22, Jacob Kjome wrote:

> Check is that is null before using it as it *will* be null if you serve 
> your app directly from a .war file rather than from a directory on the file 
> system.

Odd, I do serve mine from a .war file, however the contextPath is not
null, but points to the build directory. This is probably not true if
the war is buildt elsewhere than on the local host.

> Jake

Thanks

Øyvind


--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: Relative paths in servlets?

2003-01-06 Thread Jacob Kjome

/bar is your servlet mapping which has nothing to do with a real path on 
your system.  You want to get the real path from the base of the context:

String contextPath = getServletContext.getRealPath("/");

Check is that is null before using it as it *will* be null if you serve 
your app directly from a .war file rather than from a directory on the file 
system.

Now do contextPath+foo.html and create a File object from that.

Jake

At 02:35 PM 1/6/2003 +0100, you wrote:
Hi, could anyone tell me how to access files using relative paths from a
servlet? Say, if servlet is mapped to /bar and the file foo.html is in
the webapps top dir. How do I access the foo.html file from the servlet.
I tried ../foo.html, /foo.html and even
getServletContext().getRealPath(/bar)+"/../foo.html" but none works.

Any pointers?
--
Øyvind Hvamstad


--
To unsubscribe, e-mail:   
For additional commands, e-mail: 



RE: Relative paths in servlets?

2003-01-06 Thread Shapira, Yoav
Hi,
Did you try getServletContext().getResourceAsStream("/foo.html"); ?

Yoav Shapira
Millennium ChemInformatics


>-Original Message-
>From: Øyvind Hvamstad [mailto:[EMAIL PROTECTED]]
>Sent: Monday, January 06, 2003 8:36 AM
>To: [EMAIL PROTECTED]
>Subject: Relative paths in servlets?
>
>Hi, could anyone tell me how to access files using relative paths from a
>servlet? Say, if servlet is mapped to /bar and the file foo.html is in
>the webapps top dir. How do I access the foo.html file from the servlet.
>I tried ../foo.html, /foo.html and even
>getServletContext().getRealPath(/bar)+"/../foo.html" but none works.
>
>Any pointers?
>--
>Øyvind Hvamstad
>
>
>--
>To unsubscribe, e-mail:   [EMAIL PROTECTED]>
>For additional commands, e-mail: [EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   
For additional commands, e-mail: