In contrast to the 'webapp1' project in section 24.6.2.1, you can remove the complete functionality, in this case the display of environment variables and their values, from the source code in the HTML file Main.webpage and outsource it to the class Main.class.
<!DOCTYPE html> <html lang="de"> <head> <meta charset="UTF-8"> <title>Umgebungsvariablen</title> <style> body {font-family: Arial; font-size: 1rem; color: black;} table, td, th {border: 0.1rem solid red; border-collapse: collapse;} td, th {padding: 5px 20px 5px 20px;} <!-- Top Right Bottom Left --> </style> </head> <body> <h1>Gambas Web-Applikation</h1> <!-- The function value of the Gambas function `InsertEnvTable()` is inserted (Print) --> <% Print InsertEnvTable(); %> </body> </html>
The source text in the webpage Main.webpage now looks pleasingly clear, even if three (inline) CSS instructions have been inserted in the style tag.
Wrap the creation of the table with the two columns `Environment variable` and `Value` in the Gambas function `InsertEnvTable()` in the automatically created class file Main.class and include this function in the Main.webpage file with the syntax <% Print InsertEnvTable(); %>.
This is the content of the class file Main.class:
' Gambas class file Public Function InsertEnvTable() As String Dim sEnv, sHTML As String sHTML &= "<table>" sHTML &= "<tr>" sHTML &= "<th>Environment variable</th>" sHTML &= "<th>Value</th>" sHTML &= "</tr>" For Each sEnv In Env sHTML &= "<tr>" sHTML &= "<td>" & sEnv & "</td>" sHTML &= "<td>" & Env[sEnv] & "</td>" sHTML &= "</tr>" Next sHTML &= "</table>" sHTML &= gb.Lf '-- Output of the complete HTML source text as an HTML block Return sHTML Catch Return Error.Text End
Alternatively, the embedded HTTP server is used in the 'webapp2' project to view the HTML web pages output by the HTTP server with the table in the (debug) browser of the IDE.
Hints
Figure 24.6.2.2.1: Table with environment variables of the embedded web server
The design of the HTML page generated with F5 in the IDE, delivered by the embedded web server and displayed in the web browser is created with the 3 added (inline) CSS instructions in the Gambas class Main.class.
Consider the validation of the web pages you create as part of the development of web pages. All web pages presented to you follow the HTML5 standard. You can obtain the source code by selecting the 'Show page source code' tag in the context menu of the web page, which you call up with the right mouse button, and copying the HTML source code displayed. Validation is simple and intuitive with the tool on the website https://validator.w3.org/#validate_by_input. You can paste the generated HTML source text of the website directly into the multi-line text field and have it checked. A meaningful analysis helps you to recognise and correct errors. Or you receive the following message: Document checking completed. No errors or warnings to show.
Project