如何在Prolog动态提供的HTML页面中包含图像?

Luk*_*uka 6 image prolog swi-prolog httpserver

如果我将Prolog HTTP服务器绑定到localhost端口9000,我怎样才能让Prolog为我的图像生成正确的路径?例如,如果我的.pl文件和/ .jpg.png文件位于桌面上,如何让服务器生成如下代码:

<img src="C:\Users\Luka\\Desktop\ImageName.ext"/>,"ext"代表扩展名.我已经看了SWI-Prolog和本教程的文档,但我发现所有抽象路径都很混乱.我在Web服务器方面有很多经验,但是这有很多不同,我在理解它时遇到了很多问题.

这是我的尝试,由我在SWI-Prolog文档和上述教程中学到的(或者至少我认为的)组成:

:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_parameters)).
:- use_module(library(http/html_write)).
file_search_path('*', 'C:\\Users\\Luka\\Desktop\\').

server(Port) :-
    http_server(http_dispatch, [port(Port)]).

:- http_handler(root(.), render_base, []).
:- http_handler('/form', process_form, []).

process_form(Request) :-
    http_parameters(Request,
            [name(Name,[atom])]),
            reply_html_page('Posted data: ',['',Name]).

render_base(_Request) :-
    reply_html_page(
        title('Naslov'),
        img([src='/image.png', alt='Incident'])
    ).
Run Code Online (Sandbox Code Playgroud)

再次感谢您的巨大耐心.:-)

Cap*_*liC 7

确实,解决问题并不简单.请仔细阅读 "如何"页面,节Serving many 'server support' files.

这是我测试的代码:

http:location(images, root(images), []).
user:file_search_path(icons, '/home/carlo/prolog').
:- http_handler(images(.), serve_files_in_directory(icons), [prefix]).
Run Code Online (Sandbox Code Playgroud)

以及使用该资源的HTML

intro -->
    html([p(ol([li('select a path'),
            li('scan resources from it'),
            li('RDF-ize them'),
            li('browse with foldable SVG')
           ])),
          \sep,
          'png before', img(src='images/swipl.png'), 'png after',
          \sep,
          'jpeg before', img(src='/images/swipl.jpeg'), 'jpeg after'
         ]).
Run Code Online (Sandbox Code Playgroud)

我注意到规范img(src='images/swipl.png') img(src='/images/swipl.jpeg')工作,以及这个"功能"有助于模糊界面行为.

这里输出

在此输入图像描述

HTH