×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

servlet sending images to browser

servlet sending images to browser

servlet sending images to browser

(OP)
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

RE: servlet sending images to browser

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 http://www.joshaxtell.com/

RE: servlet sending images to browser

(OP)
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?   

RE: servlet sending images to browser

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 "http://yoursite.com/newcss.css" and have it work.

-----------------------------------------
I cannot be bought.  Find leasing information at http://www.joshaxtell.com/

RE: servlet sending images to browser

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 http://www.yahoo.com/image1.jpg, 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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close