my dog learned polymorphism*
The moose likes Servlets and the fly likes servlets + images location Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets + images location" Watch "servlets + images location" New topic
Author

servlets + images location

Andrew Mcmurray
Ranch Hand

Joined: Sep 24, 2005
Posts: 188
Hi all,

Where is the best place to put images that you want your servlet to display? How would I refer to those images from my servlet? Is it just the relative path? Is this done differently then in JSPs?

Thanks.

jutah
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61458
    
  67

The images can go anywhere where the browser can reference them via URL. The same rules apply as with JSPs: the path should be server-relative (i.e. include the context path).

Remember that regardless of whether you are using a JSP, a servlet or whatever other server-side technology, the page is just a plain old HTML file by the time it gets to the browser.

This recent post may be helpful.
[ October 18, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Makarand Parab
Ranch Hand

Joined: Dec 10, 2004
Posts: 121
Hi
The best place to keep the images when developing a web application is
1. Create a images folder inside Web Content folder. Put all your images inside that folder.

In the servlet you can use the relative path to access the images
eg.. "../images/xyz.gif"

Regards
Makarand Parab.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61458
    
  67

I highly recommend against using relative paths. It creates artificial coupling between your files that makes the web app fragile and difficult to maintain or refactor.
[ October 18, 2005: Message edited by: Bear Bibeault ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17258
    
    6

You know there was a character in "Point Break" called Johnnie Utah. By any chance are your parents big fans of that movie?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Andrew Mcmurray
Ranch Hand

Joined: Sep 24, 2005
Posts: 188
Thanks for the replies guys And yes I did get the name from point break.

Thanks,

jutah
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlets + images location