If you are trying to read from a servlet, it's:

getServletContext().getResource( "/WEB-INF/graphics/test.gif" )
getServletContext().getResourceAsStream( "/WEB-INF/graphics/test.gif" ) ;

The first one retrieves a URL object that can be used to open an input stream. The second returns an input stream you can use directly.

--David

harl3kin wrote:

Hey again,

thanks for your replies. I just want to read the resource file and I tried
the getResource() method, it can't find the resource though. When I get the
absolute path of the context, I receive the file structure where the tomcat
is installed. But does tomcat internally have the same file structure? (i.e.
local tomcat installed on C:\progs\tomcat - ist it correct that tomcat
internally tries to retrieve the wanted file from C:\progs\tomcat\... ?)
I really tried a lot. I thought the problems arise because I have a
windows-tomcat the file structure uses the wrong slashes (so I tried using
"\\" instead of "/" - did not work). So to make it really clear:
1. i have a local tomcat installed on windows
2. i have an image deployed on that tomcat on
.../webapps/test/WEB-INF/graphics/test.gif

question: how can a deployed class on the server correctly read the image that resides
on the same server?

thanks again for your help and patience,
regards,
thorsten





David Smith-2 wrote:
This is per the spec which explicitly states that the method getRealPath() will return null if the webapp is executed from an unexpanded .war file. I believe it's even in the docs for the servlet api. If however your effort is in just reading the resource, there are other methods which work regardless of being in a .war file or not -- getResource( path ) and getResourceAsStream( path ).


--David

Mark Miller wrote:
,
you could use ServletContext.getRealPath( ).  That will return the
absolute path to the file, but only if the webapp isn't packed up as .war.

--David


Why is this the case? Doesn't Tomcat extract to war to a webapp/warname
folder when it first accesses it?

- Mark

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to