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

Chris Johnston fuzzylizard at gmail.com
Tue Nov 15 20:47:10 CST 2005


On 11/15/05, Hassan Schroeder <hassan at webtuitive.com> wrote:
>
>
> I'd probably do something like, roughly:
>
> ArrayList availableImages = new ArrayList();
> /* populate as desired; could be dynamically loaded from image
> * directory, or could be static :-)
> * place ArrayList in application scope
> */
>
> /* in page or request scope */
> String imageName;
> String extension;
> /* set extension, e.g. */
> extension = "doc";
>
> if ( availableImages.contains(extension) ) {
> imageName = extension + ".png";
> }
> else {
> imageName = "default.png";
> }
>
>
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?

Chris

--
www.fuzzylizard.com <http://www.fuzzylizard.com>



More information about the thelist mailing list