[AWS] html : <img ...> doesn't find the image
Pascal Obry
pascal at obry.net
Mon Mar 9 21:57:15 CET 2009
Hi Jeremy,
> with Ada.Text_IO;
> with Ada.Integer_Text_IO;
>
> with AWS.Response;
> with AWS.Server;
> with AWS.Status;
>
> procedure Test is
>
> WS : AWS.Server.HTTP;
>
> function Main_CB (Request : in AWS.Status.Data)
> return AWS.Response.Data
> is
> URI : constant String := AWS.Status.URI (Request);
>
> begin
> return AWS.Response.Build ("text/html", "<img src=aws.png>");
First you need quote here:
return AWS.Response.Build ("text/html", "<img src=""aws.png"">");
> end Main_CB; -- or src=/aws.png
Then the question is who's going to serve your aws.png? The callback
procedure you have here respond only "<img ...>".
What happens is:
- you connect to your server
- whatever the URL passed you always get "<img src...>"
- the Web browser sees a reference to an image
- It sends back another request to the server to get the
image content
- the server send back "<img src=...>" for the image content
This is not what you meant to do :) No magic !
You need to either test for URI = "aws.png" and respond using
AWS.Response.File constructor.
Another solution (which scale better) is to place all images inside a
directory say img and create a dispatcher that will get called for each
URI whose prefix is "/img". Then you main page should look like this:
return AWS.Response.Build
("text/html", "<img src=""/img/aws.png"">");
All this is described into the AWS User's Guide.
Another comment - I understand that this is probably a test - you should
consider using the template engine and never embed any HTML into your code.
Pascal.
--
--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://www.obry.net - http://v2p.fr.eu.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver keys.gnupg.net --recv-key F949BD3B
More information about the AWS
mailing list