Difference between revisions of "TutWebAppServer Lesson 1 - Hello World"

From Overbyte
Jump to navigation Jump to search
 
Line 1: Line 1:
=== Lesson 1 : Hello World ===
 
 
 
During this lesson, you will learn how to write the simplest website. The website you'll build has only one static page displaying "Hello World".
 
During this lesson, you will learn how to write the simplest website. The website you'll build has only one static page displaying "Hello World".
  
==== Steps ====
+
== Steps ==
 
<ol>
 
<ol>
 
<li> Create a new VCL forms application.
 
<li> Create a new VCL forms application.
Line 37: Line 35:
 
</ol>
 
</ol>
 
<br>
 
<br>
==== Summary ====
+
== Summary ==
 
In this lesson you learned how to build the basic webserver to serve static page. Beside the static pages you need, there are only two Delphi code lines to write.
 
In this lesson you learned how to build the basic webserver to serve static page. Beside the static pages you need, there are only two Delphi code lines to write.
 
<br><br>
 
<br><br>

Latest revision as of 18:29, 4 May 2009

During this lesson, you will learn how to write the simplest website. The website you'll build has only one static page displaying "Hello World".

Steps

  1. Create a new VCL forms application.
    Here in the demo we use a classic GUI application. For a real application, it is likely that you'll create a service application.
  2. Rename the form "TutWebAppServerMainForm"
  3. On the form just created, drop a THttpAppSrv component.
  4. Save the files you have just created. Menu / File / Save all. Use OverbyteIcsTutWebAppServerMain.pas instead of unit1.pas and OverbyteIcsTutWebAppServer.dproj instead of project1.dproj.
  5. Hit F9 to compile and run the projet. You should get no error and a blank form. If you have errors, then it is likely you have ICS incorrectly installed. Terminate the application.
  6. Select the THttpAppSrv you just dropped on a form. Hit F11 to show the oject inspector and set a few property values:
    Name HttpAppSrv1
    Port 20080
    DocDir c:\icstutorial\wwwroot
    TemplateDir c:\icstutorial\templates
    DefaultDoc index.html
  7. Create the document directory "c:\icstutorial\wwwroot" and the templates directory "c:\icstutorial\templates".
  8. Create our static html page: Menu / File / New / Others / Web document / HTML Page. Just enter the body text "Hello World" and save the file as "c:\icstutorial\wwwroot\index.html"
  9. Add a FormShow event handler to TutWebAppServerMainForm with the code:
    HttpAppSrv1.AddGetAllowedPath('/', afBeginBy);
    HttpAppSrv1.Start;
  10. Hit CTRL-SHIFT-S to save all.
  11. Hit F9 to compile and run the application. You still get an empty form, but actually you already have a web server running ! Depending on your OS and security settings, you may get a message asking you to block or allow the application. Be sure to allow it.
  12. Now enter the url: "http://127.0.0.1:20080" into your favorite browser. You should get your marvelous "Hello World" static page.


Summary

In this lesson you learned how to build the basic webserver to serve static page. Beside the static pages you need, there are only two Delphi code lines to write.

Next lesson: Hello Today
Tutorial presentation: TutWebAppServer