dreamweaver| Static | News system
Objective
The "news system" seems to be the first lesson of all friends who learn Dreamweaver Ultradev (hereinafter referred to as UD), what!!! We're going to do the news system again today! Everybody's going to be here! Ah, today to you are able to generate static *.htm page of the news system Oh!
What is the so-called static page of the news system? We look at Sina's news page, address such as: http://news.sina.com.cn/c/2002-05-23/1558584195.html. How does this address end with *.htm? We use ASP to do, not all is like http://news.sina.com/news.asp?ID=242553? Is Sina's news all manually added? A friend of the forum asked. The answer, of course, is not (if so, Sina's backstage managers will be typing a short hand, ha)! In fact, the news is still in the form of a database added, but the production of the same time using the FSO ("FileSystemObject", is what we call the file access component), the contents of the database written as a static *.htm page, so what is the benefit? When the site traffic is too large, our ASP is busy, a large number of database retrieval query, will let our server can not bear, if the request is static page, it greatly reduced the load of the server, speed of course also fast!
Well, is not a bit interested, and below we talk about the requirements of the program and the main points of production:
1, Server System: Win2000 IIS5.0 or IIS4.0 (strongly recommended);
2, your system or remote server must support the FSO (FileSystemObject file read and write);
3, in the process of production we have to learn to separate UD generated code (also allows us to understand UD make people "horror" of the Code);
4, part of the handwriting code, combined with UD code production (never opened the code window friends to be aware of OH);
Ok! Ready to go! Let's get started!
On: The addition of news
1, page list. In this simple news system, we need to use the following pages: add.asp (Add News), browse.asp (news browsing), del.asp (delete news), example_updata.asp (template modification), save.asp (Save News), Ok.htm (Success page), updata.asp (Modify News), updata_save.asp (save changes)
2, database preparation. Set up a database (here we use Access2000) file: Asp2htm.mdb, built 2 tables: T_news,t_example, detailed as shown:
3, the establishment of templates. What does a template do? It's the last news page we've ever seen, just like the news system we used to do, but here we just use it for a ride. We create a page with any name, such as: Example.htm (click to view, you can save this page as Example.htm), we can write in the place where we want to display news content: E_title (title), E_content (content), E_ Date (time). Of course we can make a page ourselves, the key is to have this variable, the role is to let the database content to replace it, so very important. Then we go to Example.htm's Code window, select all the code, copy it, open the database file Asp2htm.mdb, search a new record in the T_example table, add the code just copied. As shown in figure:
4, add News page add.asp. This page is primarily a form that works as shown:
The names of the form's items in the diagram follow the settings in the figure. We see that there are a few items in the form that have already been filled out and we will not take care of it. Open the Server Behavior panel (Window---> Server behaviors), add an Insert record behavior, this I think we are very familiar with, do not talk about, and the form of each corresponding good, the successful page to ok.htm page, OK.
Next we're going to have to do an operation on UD's code. Go to the Code window and copy the code from scratch to the
<% @LANGUAGE = "VBSCRIPT"%>
<!--#include file= ". /connections/asp2htm.asp "-->
....................
....................
....................
If (MM_editRedirectUrl <> "") Then
Response.Redirect (MM_editRedirectUrl)
End If
End If
End If
%>
Next, open the Save.asp page (which can be an empty page), paste the code into it, and save it. So we'll separate the added record code generated by the UD Oh! Finally, to send the form to the Save.asp page, send the Type "POST", action= "save.asp".
5, use the time to do file names and get static *.htm page save path. Here is a handwritten code, mainly a function to make the current time as a filename, as if the current time. htm, which avoids the problem of duplicate file names. The functions are as follows:
<%
function Makefilename (fname)
FName = Now ()
fname = replace (fname, "-", "")
fname = replace (fname, "", "")
fname = replace (fname, ":", "")
fname = replace (fname, "PM", "")
fname = replace (fname, "AM", "")
fname = replace (fname, "a.m.", "")
fname = replace (fname, "PM", "")
Makefilename=fname & ". htm"
End Function
%>
Here's the code to get the file save path:
<%
Dim fname
Dim filepath
FName = Makefilename (now ()) ' filename
Filepath= (".. /newsfile/"&fname)
%>
Copy the two pieces of code to the
This is the filename.
<input type= "text" name= "N_filename" size= "" value= "<%=fname%>" >
This is the path of the
<input type= "text" name= "N_filepath" value= "<%=filepath%>" size= ">"
It's time.
<input type= "text" name= "n_date" value= "<%=now"%> "size=" >
OK, let's take a look at the add.asp, as shown on the image just now!
6, Save the news, generate *.htm static page save.asp page. We have just copied the add.asp code, and if we run the add.asp page directly, we can insert the record into the database, and we are now going to write this record in *.htm form.
Go to the Design window, open the Server Behavior Panel (window--> server behaviors), and add a recordset for the template, as shown in:
Go to the Code window, then we will add the FSO code to write the file, note:
<% ' This function dowhitespace is used to convert spaces and carriage returns, so that our long speeches can be displayed properly%>
<script Runat=server language=vbscript>
function DoWhiteSpace (str)
DoWhiteSpace = replace ((replace (str, VBCRLF, <br>)), Chr (+) &CHR (32), "")
End Function
</SCRIPT>
<%
Dim N_title
Dim n_content
Dim n_date
Dim fname
Dim filepath
Dim Postpath
fname = Request.Form ("n_filename") ' Gets the pass value of the form
N_title=request.form ("N_title")
N_content=dowhitespace (Request.Form ("N_content"))
N_date=request.form ("N_date")
Filepath=request.form ("N_filepath") ' File path
Pencat=rs. Fields.item ("E_meno"). Value ' replaces content in the template with the input
Pencat=replace (Pencat, "E_title", N_title)
Pencat=replace (Pencat, "e_content", N_ Content)
Pencat=replace (Pencat, "E_date", n_date)
Write data dynamic content as a static file
Set FSO = Server.CreateObject (" Scripting.FileSystemObject ")
Set fout = fso. CreateTextFile (Server.MapPath (filepath))
Fout. WriteLine pencat
Fout.close
%>
Copies the code, pasted to the back of the Recordset RS, before the code copied from the Add.asp, in the following location:
<%
Set rs = Server.CreateObject ("ADODB.") Recordset ")
Rs. ActiveConnection = mm_asp2htm_string
Rs. Source = "SELECT * from T_example"
Rs. CursorType = 0
Rs. CursorLocation = 2
Rs. LockType = 3
Rs. Open ()
rs_numrows = 0
%>
Posted here
<%
' * * Edit operations:declare variables
MM_editAction = CStr (Request ("URL"))
If (Request.QueryString <> "") Then
MM_editAction = mm_editaction & "?" & Request.QueryString
End If
............
The rest, and some HTML code (tags
7, Add Success page ok.htm and browse page browse.asp. The Success page ok.htm, in the simplest, we can write "operation successful", then write a "news browsing" below, connect to browse.asp.
Browse Page browse.asp is also relatively simple, we first set up a recordset, the following figure:
Then, add a 1*2 table on the page, insert a record, and do the repeat area, as shown in the following example:
Select {Rsbrowse.n_title} and insert the record <%= (RsBrowse.Fields.Item ("N_filepath") on the property properties panel--->link. Value)%>, as shown in figure:
ok! now browse to see if you can see the news we just added!!
So far we've seen small results! Is it a sense of accomplishment? But that's far from enough Oh! We also need to be able to delete, update also can modify the style of our news page and so on!
Next page