Recommended: Use asp to automatically parse the image address in the web page Now the HTML editor based on WEB pages is being used more and more widely in the news system and article system. A web page can maintain its original style as soon as it sticks, and the pictures can also be maintained on this page. However, during use, if the image on the pasted page is deleted, it will
ASP is a technology launched by Microsoft to replace the universal gateway interface. Its full name is Active Server Pages. It is a web server-side running environment. ASP itself contains VBScript and javascript engines, allowing scripts to be embedded directly into HTML. Now I will share with you some tips on how we use ASP.
1. News column
Most web pages have news bars to display the topic of recent news. Click this topic to view detailed reports. If you write them one by one on the web page every day, it would be too troublesome to create links in turn. How to make it automatically update based on the file?
1. Preparation:
1) Create a folder and name it news, assuming it is stored in D:/ASP/ directory;
2) Write the detailed content of each news into a file, and the naming form of this file is: x (newstime).htm. Where x is the theme of this news, and newstime is the time when the news is released (written in the order of year-month-day). Why do you write like this? You will know after reading the algorithm ideas and source programs below.
2. Algorithm idea: For files in the news folder, sort from large to small according to the time of the news release in their file names (i.e. the content in brackets). In this way, the latest news ranks at the top. As long as the top several file names in the news folder are displayed in the corresponding position of the web page, the latest news can be displayed in the news column as described in 1.
3. Source block (written in VBScript)
| The following is the quoted content: <% Dim fs, f, f1, fc, filenum dim count dim i,j,t1,t2 dim file(100) dim mystr(100) 'Standard of date in the file count=0 Set fs = CreateObject(Scripting.FileSystemObject) Set f = fs.GetFolder(D:/ASP/news) Set fc = f.Files for each f1 in fc count=count 1 'Count the number of files file(count)=fs.getbasename(f1) 'Tag file base name mypos=InStr(1, file(count), () ') position in the file base name 'Date string in file base name mystr(count) = Mid(file(count), mypos 1, Len(file(count)) - (mypos 1)) next for i=1 to count for j=1 to count-i if mystr(j)<mystr(j 1) then t1=file(j) file(j)=file(j 1 file(j 1)=t1 t2=mystr(j) mystr(j)=mystr(j 1) mystr(j 1)=t2 end if next next j=1 if count<10 then 'The news column shows 10 news temcount=count else temcount=10 end if do while j<=temcount%> <a href=file:///D:/ASP/news/<%=file(j)%>.htm target=new_window><%=file(j)%> </a> <% j=j 1 loop %> |
4. Updated news column content:
As long as you develop good writing habits, make the name of the news follow the requirements of 1, and then save the written files into the news folder, the latest 10 news will automatically display.
2. Bulletin board
In addition to the news column, the most commonly used one is the bulletin board, which is mainly used to display some important notifications. Of course, these notifications need to be changed frequently. Will you let users go to the source program to modify every time they change the content of the announcement? Of course not. We must provide a maintenance interface to the user, so that as long as the user enters a notification, the notification content will naturally be displayed in the bulletin board on the web page.
1. The key to solving this problem lies in the flexible application of FileSystemObject objects and TextStream objects. In actual applications, you do not need to create a TextStream object by yourself, because as long as you open the file with the FileSystemObject object, the system will automatically create a TextStream object. That is, once the OpenTextFile or CreateTextFile method is called, the TextStream object will be passed back.
2. There are three relevant files required: update.asp, announcement.asp, maintenance text.txt, and save them in the d:/ASP/maintain directory.
3. The main functions and source blocks of the three files:
1) Update.asp
The main function is to let the user enter the announcement to display, verify whether the input content is empty. If it is not empty, it will be submitted to the announcement.asp program for processing.
| The following is the quoted content: <html> <head> <meta http-equiv=Content-Type content=text/html; charset=gb2312> <meta name=GENERATOR content=Microsoft FrontPage 4.0> <meta name=ProgId content=FrontPage.Editor.Document> <title>Update bulletin board content</title> </head> <body> <script language=vbscript> function datacheck() dim msg,errflag errflag=true if len(trim(maintain.t1.value))=0 then focusto(0) errflag=false msg=Please enter the announcement content to be submitted end if if (errflag=false) then msgbox msg,64,oh no! exit function end if datacheck=errflag maintain.submit end function sub focusto(x) document.maintain.elements(x).focus() end sub </script> ①<form method=POST action=announcement.asp name=maintain> <p><input type=text name=t1 size=84><input type=reset value=rewrite name=B2> <input type=button value=Submit name=B1 onclick=datacheck()></p> <hr color=#FF99FF size=1> </form> </body> </html> |
The action=Announcement.asp section in statement ① points out that the program to be started after form is submitted is announcement.asp.
2) Announcement.asp
The maintenance text .txt file is read and write through the FileSystemObject object and the TextScream object, so that the content of the top 5 lines of this file is the announcement to be displayed in the bulletin board.
| The following is the quoted content: <% dim str str=request.form(t1) dim s(5) const forreading=1,forwriting=2 dim fso,myfile set fso=server.createobject(scripting.FileSystemObject) set myfile=fso.opentextfile(maintain text.txt,forreading)'Open file in Reading mode for i=1 to 5 'The bulletin board displays 5 announcements in total s(i)=myfile.readline'Read the file content next myfile.close set myfile=fso.opentextfile(maintain text.txt,forwriting,true) 'Open file in writing mode myfile.writeline str for i=1 to 4 myfile.writeline s(i) 'Write data back to file next myfile.close %> |
3) Maintain text.txt
This file starts empty, and after entering an announcement from the interface displayed in update .asp, the contents of this file are automatically written.
4. Add the following code to the code segment where the announcement location is to display the update announcement in the home page file (usually default.asp) to display the updated announcement.
| The following is the quoted content: <marquee scrolllamount=2 scrolldelay=50 direction=up width=223 height=133 id=a onmouseover=a.stop() onmouseout=a.start()>'Scroll up and down the bulletin board <% Dim s(20) Dim fso, MyFile Set fso = CreateObject(Scripting.FileSystemObject) Set MyFile = fso.OpenTextFile(D:/ASP/maintain/maintain text.txt,1,true) for i=1 to 5 ReadLineTextFile=MyFile.ReadLine s(i)=ReadLineTextFile response.write ★ & s(i) response.write <br> next %> </marquee> |
The above two tips can solve many such problems by learning from one example. Web design enthusiasts might as well give it a try.
Share: The deepest understanding of session and cookies Let’s talk about session’s debate on SESSION, but there should be more than 90 people who can understand SESSION. But let me tell you, don’t think you are old~ Some people agree with SESSION, while others disagree. But what exactly should I say about this question? Why not listen