[thelist] need help loading default image, then changing it with actual image

Hassan Schroeder hassan at webtuitive.com
Tue Nov 15 21:28:57 CST 2005


Chris Johnston wrote:

> Interesting solution. Although I am not sure how I would load this
> dynamically as I am having problems getting to the correct directory within
> the JSP page.
> 
> What I have tried so far is something like this:
> 
> File file = new File("images/big/" + document.getFileType() + ".png");
> boolean iconExists = file.exists();
> 
> but the file object does not use the web path, it uses one relative to where
> Tomcat started from so it is looking in the wrong directory. Currently, it
> is looking in
> 
> C:\apps\Tomcat\bin\images\big\
> 
> Is there anyway to grab the web directory from within a JSP page and use
> that path/directory in a java scriptlet?

ServletContext.getRealPath() would be one approach. If you were
going to create the ArrayList dynamically, a ServletContextListener
would probably be the best place to initialize it.

Alternatively, you could specify the absolute path to your images
directory in a .properties file in 'WEB-INF/classes', or as an
environment variable in web.xml.

Always more than one way to do it :-)

-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                          dream.  code.





More information about the thelist mailing list