KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using the command SEND HTML FILE in contextual mode
PRODUCT: 4D | VERSION: 6.0 | PLATFORM: Mac & Win
Published On: February 11, 2000

When working with the web server in Versions 6 and 6.5 of 4D and 4D Server in Contextual mode, there is a command SEND HTML FILE that allows the programmer to send a HTML text file to the web browser. If the command SEND HTML FILE is used repeatedly, the programmer must be careful not to fill the stack of the Web Connection process. This tech tip shows one correct way of using SEND HTML FILE and not filling the stack.

Every time a command like SEND HTML FILE is executed the program uses some memory to complete the actions of that command. When the command is completed, the program releases the memory. This temporary memory is referred to as the stack. If a command is executed again before the previous time it was executed is completed, the amount of stack space used will grow. If the command is executed enough times the process will run out of stack space. If there is no available stack space, the program cannot perform anymore new actions till some stack space is freed.

In the Examples Downloads area and in the Web Developer's Corner, there is a database called "Stack Space Error DB" which shows how to allow 4D to completely execute SEND HTML FILE before issuing the command again. The answer is to execute SEND HTML FILE with a null string (e.g. SEND HTML FILE("") ) before executing SEND HTML FILE again. The steps go something like this:


  1. 4D executes: SEND HTML FILE("XXX.shtm")
  2. The browser executes <a href="/4DMethod/Go_Back">Done</a>
  3. This executes a method called "Go_Back" in 4D
  4. Go_Back contains the code SEND HTML FILE("")
  5. 4D completes executing the command SEND HTML FILE("XXX.shtm")


Note, this issue only happens 4D web server is running in contextual mode and not non-contextual mode.

Below are the contents of methods and html files use in the database mentioned earlier, "Stack Space Error DB":






Cut and Paste the following code example into your own 4D project



` 4D method: On Web Connection


C_TEXT($1;$2;$3;$4;$5;$6)

C_LONGINT($i)


SEND HTML FILE("intro.shtm")


For ($i;1;15)

SEND HTML FILE("test.shtm")
SEND HTML FILE("test2.shtm")
End for


BEEP
BEEP
SEND HTML FILE("the_end.shtm")







Cut and Paste the following code example into your own 4D project


` method: Go_Back


`Generic method to return from a Send HTML File
`Call this as a /4DMETHOD URL


C_TEXT($1)


SEND HTML FILE("")







Cut and Paste the following code example into your own 4D project


` method: Send_HTM


` execute this method enough times without exiting out of the last time
` the method was executed and you will run out of stack space


C_TEXT($1)


SEND HTML FILE("test.shtm")







Cut and Paste the following code example into your own html editor


<!-- file: intro.shtm -->


<html>
<head> <title>4D Web Context Mode Demo: Stack Error Example</title> </head>
<body>
<p>This is a demonstration for executing the command </p>
<p>Send HTML File, while in Contextual mode, without getting </p>
<p>an "Out of Stack" error. For details see tech tip:</p>
<p>Using the Command SEND HTML FILE in Contextual Mode</p><BR>
<p>Directions:</p>
<p>Click on the link: Bad Example Link to get Out of Stack error.</p>
<p>Click on the link: Good Example Link to see correct result.</p><BR>
<p><a href="/4DMethod/Go_Back">Start now...</a></p>
</body>
</html>







Cut and Paste the following code example into your own html editor


<!-- HTML file: test.shtm -->


<html>
<head> <title>4D Web Context Mode Demo: Stack Error Example</title> </head>
<body>
<h2>Test page 1.</h2><BR>
<p><a href="/4DMethod/Go_Back">Good Example Link</a></p>
<p><a href="/4DMethod/Send_HTM">Bad Example Link</a></p>
</body>
</html>







Cut and Paste the following code example into your ownhtml editor


<!-- HTML file: test2.shtm -->


<html>
<head> <title>4D Web Context Mode Demo: Stack Error Example</title> </head>
<body>
<h2>Test page 2.</h2><BR>
<p><a href="/4DMethod/Go_Back">Good Example Link</a></p>
<p><a href="/4DMethod/Send_HTM">Bad Example Link</a></p>
</body>
</html>







Cut and Paste the following code example into your ownhtml editor


<!-- HTML file: the_end.shtm -->


<html>
<head> <title>4D Web Context Mode Demo: Stack Error Example</title> </head>
<body>
<p>If you got this far, then everything worked correctly.</p><BR>
</body>
</html