Your First Time with the Web Server

4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next

version 6.5 (Modified)


Example in contextual mode

This section gives a simple example of instant database publication in contextual mode. This automatic mode can be used more particularly for Intranet servers. It illustrates the basic principles of 4D Web server operation.

The structure of this database (given at the end of this section) is simple: the database is made of one table, an input form, an output form and a menu bar. The Home page is customized. The database is published as a Web server.

1. Connect to the Web server database

Connect to the Web Server by opening the database on a Web browser. You get the following Home Web page:

2. Display and browse the records

Click on the linked text List Existing Records. This presents the Web equivalent of a 4D Display Selection screen:

At this point, you can browse the records at your convenience. After you click the Done button, you go back to the Web site Home page.

3. Add records

In the Web site Home page, click on the Linked text Add Some Records to display the Web equivalent of a 4D Add Record screen:

You can add as many as records as you wish. When you are done, click the Cancel button (the one with the red cross) to return to the Web site Home page.

4. List or add records in the Main menu

In the Home page, click the Go to Main Menu Bar button. This exits the Home page and presents the Web equivalent of the 4D Custom menu bar:

At this point, clicking on each menu item allows you to List or Add records: the same 4D methods that were used from the Home page are associated to the menu items.

5. Terminate the connection

When you are done, just quit your browser. 4D will terminate the Web connection process once the timeout delay has elapsed.

Initiating a Web connection in contextual mode

Each time a Web browser connects to a 4D database published as a Web Server in contextual mode, 4D performs the following actions:

It executes the On Web Authentication database method, if it exists.

If this method returns True or does not exist, it executes the On Web Connection database method, if it exists.

If there is no such database method or if the method has completed, 4D then displays the Default Home page defined in the Preferences, if any.

If no Default home page is defined, 4D then displays the current menu bar (by default menu bar #1), if it exists.

If there is neither a Default Home page nor a menu bar, 4D displays a default Web page that states: "This database has not been setup for the Web yet".

The following diagram summarizes these actions:

The On Web connection database method can call any of the project methods or forms defined in the database as well as HTML pages. The database method can actually handle the whole session.

A Web connection to 4D or 4D Server is not the same as a Client/Server connection. The HTTP protocol, which supports HTML and the Web, is not a "session-based" protocol; it is rather a "request-based" protocol. In Client/Server, you connect, work in a session, and then disconnect from the server. With HTTP, each time you perform an action that requires the attention of or an action from the Web Server, a request is sent to the server. In short, an HTTP request can be understood as the sequence "Connect+Request+Wait for reply+Disconnect."

In contextual mode, in order to run a Client/Server session via HTTP, by default 4D maintains, through a transparent encoding of the URLs, a context that uniquely identifies your Web connection and at the same time associates the connection to the 4D process handling the connection.

However, in this mode 4D has no way to provide an equivalent of the Client/Server disconnect action that terminates a session. That is the reason why the termination of a Client/Server session is handled through a timeout scheme. The 4D process handling the Web connection terminates after no activity has been detected for a delay time equal to the database Web timeout settings.

Database and Web Server in one

You can completely manage a 4D Web Server session using 4D Menus Bars, Forms and Methods in contextual mode. In the preceding example, listing and adding records was performed by simple 4D methods and forms. If we had not included an HTML home page, a Web browser would have obtained, upon connection, the menu bar #1 shown.

If we eliminate the HTML home page, building a Web Server supporting database Client/Server transactions consists of building a 4D database on Windows or Macintosh, for one or multiple users. The following steps explain the process of creating the example database in this way.

Here is the Structure of the example database:

Input and Output forms are added to enable you to work with records.

Menu bar #1 is added to enable you to work with Custom menus and to support Web connections.

The two following project methods are written.

      ` M_ADD_RECORDS project method
   C_TEXT($1)  ` This parameter MUST be explicitly declared
   Repeat
      ADD RECORD ([Clients])
   Until (OK=0)
      ` M_LIST_RECORDS project method
   C_TEXT($1)  ` This parameter MUST be explicitly declared
   ALL RECORDS ([Clients])
   MODIFY SELECTION([Clients])

The "Start a New Process" attribute is assigned to each method.

The Web server starts up in contextual mode and a default home page is defined in the database Preferences:

The home page contains two links,"Add Some Records" and "List Existing Records," that trigger the execution of the 4D project methods M_ADD_RECORDS and M_LIST_RECORDS through their URLs. The convention is quite simple: any HTML object can link to a project method of your database with the URL "/4DMETHOD/Name_of_your_Method". The Available through 4DACTION, 4D METHOD and 4D SCRIPT attribute must be associated with each method called using 4DMETHOD:

Once these links have been defined, when the Web browser sends back the URL, 4D executes the project method specified after the /4DMETHOD/ keyword. Then, after the project method has been completed, you go back to the HTML page that triggered its execution. Note that the project method can itself display 4D forms, other HTML pages, and so on.

Your 4D-based Web Site can be a completely 4D-based system or a combination of 4D forms and HTML pages. The interesting point in using HTML pages from within your 4D database is that you benefit from both the 4D and HTML development environments. Remember, you do not have to use HTML pages if you do not want to

The HTML home page in this example includes a button used to submit a record. There are three types of HTML buttons: normal, submit, and reset.

Normal - Normal buttons can be attributed an URL that refers to a 4D method using the /4DMETHOD/ keyword. Normal buttons are used for navigation purposes.

Submit - Submit buttons submit the form with the values entered by the user (if any) to the Web server. They are useful for handling data entry that you prefer to perform via an HTML page rather than a plain 4D form

Reset - Reset buttons are not very useful within a 4D development: they clear the form of the values entered by the user (if any) and does not send any request to the server.

While integrating HTML pages into 4D, you will typically use normal or submit type buttons. The code of the home page button is the following: INPUT TYPE="SUBMIT" NAME="/4DMETHOD/GO_MAIN_MENUBAR"

To submit the HTML form on the 4D side, you need to specify the POST action 4D method that will be executed by 4D after the form is submitted.

To do this, it must contain the line FORM ACTION="/4DMETHOD/GO_MAIN_MENU_BAR" METHOD="POST"

The GO_MAIN_MENU_BAR project method is the following:

   SET HOME PAGE("")

In this example, this method has only one purpose: getting out of the current default home page displayed on the Web browser and then sending the current menu bar. 4D switches to the menu bar #1 of the database.

That is it!

In less than five minutes, you have created a 4D database that is both a locally operable database and a Web Server that you can publish on your Intranet network or on the Internet.

See Also

SEND HTML FILE, SET WEB DISPLAY LIMITS, SET WEB TIMEOUT, START WEB SERVER, STOP WEB SERVER.


4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next