Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

servlet sending images to browser

Status
Not open for further replies.

andyberlin2000

Programmer
May 12, 2004
18
DE
I want to send my webpage from a servlet, that dynamically creates the HTML-page from a tmeplate. Of course there will be pictures on the website. All book examples show how to handle one file if you know that you want to send THIS ONE file.

Sorry for the question but none of my books explains the MECHANISM!

I couldn't see any pictures - obviously they are not send.
The HTML page itself works fine. From the servlet do I have to send every single file (img, css) one by one?

How about the CSS file and it's images ?
Do I really have to send every single image "by hand", having to control even all CSS background images and my app's images by using getRealPath and the filename?
Where do I send them to?

Do I have to scan my HTML and my CSS for file names to be able to put my output together DYNAMICALLY?

By the way - I have no idea what getRealPath() is doing - I definitely don't get the path. ( .../WEB-INF/classes/ )

Please explain the mechanism shortly to me. I always thought ressources that are not there yet would be REQUESTED by the browser....

Thank you in advance
Andreas
 
If I understand you correctly, you want to know if its possible to send the html and images all in one? As far as I know, thats not possible. So, the user requests the page, gets the html to determine what else it's supposed to have, and requests each resource (file) individually. Are you dynamically generating images and css? If not, then you're making things more complicated than they need to be. Perhaps you should post some code, what is happening, and what you want to happen.

-----------------------------------------
I cannot be bought. Find leasing information at
 
To jaxtell:

Maybe I have to ask more clearly:

I send a page (HTML only).
It is presented by the browser.
All images (NOT EXPLICITLY SEND by my servlet) and all CSS information from the css file
( /css/xyz.css, NOT EXPLICITLY SEND by my servlet ) are ignored/missing.

I don't want to send what I don't have to send. I dont't understand why my webpage is uncomplete.
My understanding up to now is that FILES that are not there will be REQUESTED by the user's browser - so I don't have to take action.
But this doesn't work. That's why I asked to explain the MECHANISM - servlets may be different from HTML/PHP etc. - I don't know.

It should be no difference that I am working in an offline environment (TOMCAT) - right?
 
Is this website you're working available on the web? If so, can you send a link? What servlet container are you using? Tomcat, OC4J? Lets say you had a file newindex.html, located on your file system at /mywebsite/newindex.html. If you had /mywebsite/newcss.css, it should be accessible the same way. By default, it should be accessible the same way on the web. So if you can get to yoursite.com/newindex.html, you should be able to get to yoursite.com/newcss.css , and newindex.html should be able to reference either "./newcss.css" or " and have it work.

-----------------------------------------
I cannot be bought. Find leasing information at
 
There can be a difference that you are working in an offline environment.
If I use a computer to run Tomcat server and I cannot connect to Internet with this computer, there can be a chance of problem appearance for image file.

If you specify image path in html by no Internet connection will create broken image problem. (Because you refer image to outside server and you will require Internet connection)

if you specify image path in html by /images/image1.jpg, you are referring image on your server(that contain your html)

The general idea is the same as jaxtell said.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top