Use ISAPI to implement the automatic update of web pages
Author: Cui strong for some webmasters, the most painful thing to do daily duplication of work. For example, from the news page to remove the old news headline, replace the new news headline; if you want the reader to see the previous news, you have to change the Formfield value that changes over time. and many more. Write a WebServer's ISAPI program with Delphi, which can greatly reduce the amount of work. ---- ISAPI mode server-side server, have the following features: Small memory overhead, multiple client links with one link memory overhead; fast. Since the DLL is running once, it is still in memory. When there is a new link, the data is transmitted directly from the memory, and the speed is effectively improved. ---- I have the following functions written in Delphi4: ---- 1, automatically modify the time value of Formfield (selected) in accordance with date changes. ---- 2, automatically generate news directories. Managers simply copy new news to this directory, the program can automatically generate the page of the news home page.
---- Heart: ---- 1, search for eligible files in a directory, return handle: Handle FindFirstFile (LPCTSTSTR LPFILENAME, LPWIN32_FIND_DATA LPFILEDATA); ---- 2, the handle returned according to FindFirstFile Continue search for next File: BOOL FINDNEXTFILE (Handle HfindFile, LPWINDICEDATA); ---- 3, close the specified search handle: BOOL FINDCLOSE (Handle HfindFile); ---- 4, Win32_Find_Data This structure stores FindfirstFile and findnextFile finds the information of the file, the following structure: typedef struct _WIN32_FIND_DATA {DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName [MAX_PATH]; TCHAR cAlternateFileName [14];} WIN32_FIND_DATA; action program content: name pathinfo enabled updata WebActionItem1 / DispNews true source code is as follows: unit Unit1; interface uses Windows, Messages, SysUtils, Classes, HTTPApp, ShellApi, ExtCtrls; type TWebModule1 = class (TWebModule) Timer1: TTimer; procedure WebModule1updataAction (Sender: TObject Request: TwebRequest; Response: TWebResponse; Var Handled: Boolean; Procedure WebMod ule1WebActionItem1 Action (Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); procedure Timer1Timer (Sender: TObject); private {Private declarations} public {Public declarations} end; var WebModule1: TWebModule1; implementation {$ R * .Dfm} // // This section is to perform a DLL without an entry.
Function: Generating the home page of the news center, // Main purpose is to drop the time dynamic change of the drop-down menu. WebModule1Updata (Sender: Tobject; Request: TWebRequest; Response: TWebResponse; var handled: boolean; var dhtml: string; var i: Integer; Begin DHTML: = ''; DHTML: = DHTML '
'; DHTML: = DHTML 'Please select Date: p>'; DHTML: = "POSPNEWS" '; DHTML: = DHTML '
DHTML: = DHTML ' html>'; response.content: = DHTML; END; // Determines the file directory to display // according to the parameter transmitted by the request // and remove all HTM files from this directory // If there is no directory, send a message to the browser procedure TWebModule1 WebModule1WebAction Item1Action (Sender: TObject; request: TWebRequest; Response: TWebResponse; var Handled: Boolean);. var ReqDir: Tstrings; // save request parameters required var DHTML, SeleDir: string; var FileNameData: WIN32_FIND_DATA; var SearchFileHandle: THandle; begin ReqDir: = NIL; ReqDir:. = Request ContentFields; DHTML: = ''; DHTML: = DHTML '
'; DHTML: = DHTML '< Title> News Center Title> '; DHTML: = DHTML ' head> '; DHTML: = DHTML ' '; DHTML: = DHTML 'News Center font> p> '; // DHTML: = DHTML ReqDir.Values [' TM ']; Seledir: = Reqdir. Values [' TM ']; // get search handle SearchFileHandle: = FindFirstFile (Pchar (' C: / MyWeb / news / ' SeleDir ' /*.htm'),FileNameData); if SearchFileHandle <> INVALID_HANDLE_VALUE then begin DHTML: = DHTML '< P> FileNamedata .cfilename ' a> p>'; // Search for whose FindNextFile (SearchfileHandle, FileNameData) DO DHTML: = DHTML '