JKL Toy Company adds dynamic content with server-side includes for HTTP Server

This scenario discusses how to add dynamic content to an IBM® HTTP Server for i Web server using server-side includes.

Scenario

The JKL Toy company (a fictitious company) wants to add some dynamic content to their index file (or welcome page) on their Web site. The welcome Web page is located in /www/jkltest/htdocs. The JKL Web administrator will add the current server time to display on their Web page.

Note: Server-side includes (SSI) create dynamic Web pages by adding content to a Web page before it is sent to the browser. Server performance may be impacted when processing SSIs.

Prerequisites

Edit the index file (or welcome page) with System i Navigator

For in-depth information on how to use the System i Navigator, read the System i Navigator help installed with the product.

  1. Start System i Navigator.
  2. Expand theIBM i server the HTTP Server is installed on.

    Example: JKL_SERVER

  3. Expand File Systems > Integrated File System > Root > www > [server_name].

    Example: File Systems > Integrated File System > Root > www > jkltest

  4. Click htdocs.

    The directory htdocs is the default name of your document root provided by the Create New HTTP Server wizard.

  5. Right-click index.html.
  6. Click Rename.
  7. Rename the file index.shtml.
  8. Right-click index.shtml.
  9. Click Edit.
  10. Enter the following lines below the <BODY> tag and before the </BODY> tag:
    <p>The current server time is:
    <!--#config timefmt="%T" -->
    <!--#echo var="DATE_LOCAL" -->
    </p>
  11. Save and close the file.

See Server-side include commands for HTTP Server for more information about SSI commands.

Start the IBM Web Administration for i interface

Access the IBM Web Administration for i from your browser. For information about how to access the Web Administration for i interface, see Starting Web Administration for i.

Set up server-side includes for HTTP Server

  1. Click the Manage tab.
  2. Click the HTTP Servers subtab.
  3. Select your HTTP Server from the Server list.

    Example: JKLTEST

  4. Select Global configuration from the Server area list.
  5. Expand Server properties.
  6. Click Container Management.
  7. Click the Files tab in the form.
  8. Click Add under the Files/Files Match containers table.
  9. Select Files Match from the list in the Type column.
  10. Enter \.shtml(\..+)?$ in the File name or expression column.
  11. Click Continue.
  12. Click OK.
  13. Select Files Match \.shtml(\..+)?$ from the Server area list.
  14. Expand Server Properties.
  15. Click Dynamic Content and CGI.
  16. Click the Server Side Includes tab in the form.
  17. Select Allow server side files without CGI under Server side includes.
  18. Click OK.
  19. Select Global configuration from the Server area list.
  20. Expand Server Properties.
  21. Click General Server Configuration.
  22. Click the Welcome Pages tab in the form.
  23. Select index.html in the Welcome/index file names table.
  24. Rename the file index.shtml in the File name column.
  25. Click Continue.
  26. Click OK.

Restart your HTTP Server

Select one of the following methods below:

Manage one server

  1. Click the Manage tab.
  2. Click the HTTP Servers subtab.
  3. Select your HTTP Server from the Server list.
  4. Click the Stop icon if the server is running.
  5. Click the Start icon.

Manage all servers

  1. Click the Manage tab.
  2. Click the HTTP Servers subtab.
  3. Select All Servers from the Server list.
  4. Click the All HTTP Servers tab.
  5. Select your HTTP Server name in the table.

    Example: JKLTEST

  6. Click Stop if the server is running.
  7. Click Start.
Note: If your HTTP Server does not start, see Troubleshooting.

Test your HTTP Server

  1. Start a new Web browser.
  2. Enter http://[i_hostname]:[port] in the location or URL field.

    Example: http://jkl_server:1975

The Web page now displays the current server time.

View your HTTP Server configuration

Your configuration will look similar if you used the given example in this and previous examples.

  1. Click the Manage tab.
  2. Click the HTTP Servers subtab.
  3. Select your HTTP Server from the Server list.

    Example: JKLTEST

  4. Expand Tools.
  5. Click Display Configuration File.
Listen *:1975
DocumentRoot /www/jkltest/htdocs
TraceEnable Off
Options -FollowSymLinks 
AccessFileName .htaccess
LogFormat "%h %l %u %t \"%r\" %|s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{Cookie}n \"%r\" %t" cookie
LogFormat "%{User-agent}i" agent
LogFormat "%{Referer}i -| %U" referer
LogFormat "%h %l %u %t \"%r\" %|s %b" common
CustomLog logs/access_log combined
LogMaint logs/access_log 7 0
LogMaint logs/error_log 7 0
SetEnvIf "User-Agent" "Mozilla/2" nokeepalive
SetEnvIf "User-Agent" "JDK/1\.0" force-response-1.0
SetEnvIf "User-Agent" "Java/1\.0" force-response-1.0
SetEnvIf "User-Agent" "RealPlayer 4\.0" force-response-1.0
SetEnvIf "User-Agent" "MSIE 4\.0b2;" nokeepalive
SetEnvIf "User-Agent" "MSIE 4\.0b2;" force-response-1.0
DirectoryIndex index.shtml
<Directory />
	Require all denied
</Directory>
<Directory /www/jkltest/htdocs>
	Require all granted
</Directory>
<FilesMatch \.shtml(\..+)?$>
	Options +IncludesNoExec
	AddOutputFilter INCLUDES .shtml
</FilesMatch>