Howdy,
I agree with mech's answer: don't use file-based APIs.  Use the
ServletContext getResource() and getResourceAsStream() methods.  Use
relative links to your images.  Map your servlets in web.xml.

For example, let's say you have a servlet com.mycompany.MyServlet.  It
needs to access images from the images directory under your webapp root.

In web.xml:
<servlet>
  <servlet-name>MyServletName</servlet-name>
  <servlet-class>com.mycompany.MyServlet</servlet-class>
</servlet>

<servlet-mapping>
  <servlet-name>MyServletName</servlet-name>
  <url-pattern>/MyServlet</url-pattern>
</servlet-mapping>

Then MyServlet, having an PrintWriter out, would add links to images as
follows:
out.println("<img src=\"./images/img1.jpg\"></img>");
etc etc.

Yoav Shapira
Millennium ChemInformatics


>-----Original Message-----
>From: joe udder [mailto:[EMAIL PROTECTED]]
>Sent: Sunday, January 19, 2003 6:38 AM
>To: [EMAIL PROTECTED]
>Subject: Some advice on getting webapp-root and reading/writing
>
>Hello.
>
>Does anyone have some advice to give me on the following ideas?
>
>
>My first problem is to find the correct path to my files.
>Is there a method to get the "document-root" of my webapp, so I only
need
>to
>append "Images/jpg" and "WEB-INF/settings" to the path?
>
>I suppose using URL's is the most platform independent method?
>
>
>Example:
>
>My webapp is located in "/var/www/waTest/WEB-INF/",
>and the JPG's are in "/var/www/waTest/Images/jpg/".
>
>Finally the XML's are located in "/var/www/waTest/WEB-INF/settings/".
>
>
>
>The second problem is how to read/write the files, should I use
FileReader
>or is there a better solution for webapps?
>
>TIA
>
>/ju
>
>
>_________________________________________________________________
>Protect your PC - get McAfee.com VirusScan Online
>http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
>
>
>--
>To unsubscribe, e-mail:   <mailto:tomcat-user-
>[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:tomcat-user-
>[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to