perlincludecgiserver-side-includes

How to include CGI script inside HTML document?


I have to include my CGI script login.pl inside an HTML document index.html. I googled for answers and was surprised to find out that it was hard to get a definitive answer to this question. Some suggest using server side includes, but as far as I understand those are used for putting HTML inside of CGI, which is not what I want. I know that in JSP and PHP one can use tags like <% %> and php tags to include code inside of HTML document. Is there a similar construct for CGI? P.S. I am using CGI.pm framework and want to run output of login.pl inside of index.html.


Solution

  • What you are looking for is HTML::Template or Template::Toolkit. Either of these will allow you to put tags in your HTML file and your CGI script can populate the data.

    Note that you will be posting to or getting from the CGI script which will read the HTML file, populate it and then send built HTML file to the client. The client's browser would not be accessing the HTML file directly.

    In your case, the client's browser will post to login.pl and then, on the server, the perl script will run and build the HTML file and serve it to the client.