I. Principles:
1. Construct an HTTP request using JavaScript to request the image path and image description data from the background database.
2. Use the returned image data to construct an image path array and an image description array.
3. Construct an IMG object
4. Use the Javascript timing function to control the SRC and title attributes of the IMG object and switch between the image path array and image description array elements.
Ii. File composition:
FrontPage. asp
Loadpicturesource. asp
Conn. asp
Site. MDB
Iii. Detailed Design:
1. The client requests FrontPage. asp: http-> FrontPage. asp
2. FrontPage. asp calls loadpicturesource. asp to obtain image data: FrontPage. asp-> loadpicturesource. asp
3. loadpicturesource. asp call site. mdb to obtain data storage: loadpicturesource. asp-> site. MDB
4. FrontPage. asp constructs the image path array and image description array by calling the returned data.
5. FrontPage. asp starts the setinterval scheduled function for automatic control.
Iv. File Content:
========================================================== ==========================================
FrontPage. asp
========================================================== ==========================================
<! -- # Include file = "conn. asp" -->
<%
Dim RS, ssql, soutput, defaultpicture, defaultdescription, interval
'Refresh frequency
Interval = 5000
'Default image and default description
Set rs = server. Createobject ("ADODB. recordset ")
Ssql = "select top 1 * From pictureset where picname = 'homepage image' order by updatedate DESC"
Rs. Open ssql, Conn, 1, 1
If not Rs. bof and not Rs. EOF then
Defaultpicture = RS ("picpath ")
Defaultdescription = RS ("pictitle ")
End if
Rs. Close
Conn. Close
Set rs = nothing
Set conn = nothing
Defaultdescription = "image news:" & defaultdescription & "(click an image to view the magnified effect )"
%>
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> </title>
<Meta name = "generator" content = "editplus">
<Meta name = "author" content = "">
<Meta name = "keywords" content = "">
<Meta name = "Description" content = "">
<Script language = "JavaScript">
<! --
VaR arraysrc;
VaR arrayalt;
VaR picnamecounter = 0;
Function getserverdata (objstrname, objstrvalue, serverpage)
{
String = escape (objstrname) + "=" + escape (objstrvalue );
VaR objxmlhttp = NULL;
Try
{
Objxmlhttp = new activexobject ("msxml2.xmlhttp ");
}
Catch (E)
{
Try
{
Objxmlhttp = new activexobject ("Microsoft. XMLHTTP ");
}
Catch (E2 ){}
}
Objxmlhttp. Open ("Post", serverpage, false );
Objxmlhttp. setRequestHeader ("Content-Length", String. Length );
Objxmlhttp. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
Objxmlhttp. Send (string );
Return objxmlhttp. responsetext;
}
Function initialize ()
{
VaR returnsrc = getserverdata ("picturesrc", "picturesrc", "loaddisplaypicture. asp ");
Arraysrc = returnsrc. Split ("| ");
VaR returnalt = getserverdata ("picturealt", "picturealt", "loaddisplaypicture. asp ");
Arrayalt = returnalt. Split ("| ");
Setinterval ("pictureload ()", <% = interval %> );
}
Function pictureload ()
{
Document. All ('mainpic '). src = arraysrc [picnamecounter]. tostring ();
Document. All ('mainpic '). Title = arrayalt [picnamecounter]. tostring ();
Document. All ('picturedescption '). innertext = "image news:" + arrayalt [picnamecounter]. tostring () + "(click the image to view the zoom in effect )";
Picnamecounter = picnamecounter + 1;
If (picnamecounter> 9 | picnamecounter> arraysrc. Length-1)
{
Picnamecounter = 0;
}
}
Function showfull ()
{
VaR newwin = Window. open ();
Newwin.doc ument. write (" ");
Newwin.doc ument. Close ();
}
// -->
</SCRIPT>
</Head>
<Body>
<Table width = "100%" Height = "224" border = "0" cellpadding = "0" cellspacing = "0">
<Tr>
<TD Height = "0.5px" colspan = "3" bgcolor = <% = bgcolor %> & nbsp; </TD>
</Tr>
<Tr>
<TD Height = "6" bordercolor = "#000000">
<! ------------------ Image switching section ------------------>
width = "280" Height = "186" onclick = "showfull (); "Title = <% = defaultdescription %>
<TD width = "1%" bgcolor = <% = bgcolor %> </TD>
<TD width = "65%" bordercolor = "#000000" bgcolor = "# ffffff">
<! ------------------ Text and news section ---------------->
<Script language = "JavaScript" src = "Owen. asp? N = 7 "> </SCRIPT>
</TD>
</Tr>
<Tr>
<TD colspan = "3">
<Table>
<Tr>
<TD align = "Left" width = 88%> <font size = 2px> <a name = "picturedescption"> <% = defaultdescription %> </a> </font> </TD>
<TD align = "right"> <a href = "default_all.asp" target = "_ blank"> <font size = 2px> More news... </font> </a> </TD>
</Tr>
</Table>
</TD>
</Tr>
<Tr>
<TD Height = "0.5px" colspan = "3" bgcolor = <% = bgcolor %> & nbsp; </TD>
</Tr>
</Table>
<Script language = JavaScript> initialize (); </SCRIPT>
</Body>
</Html>
========================================================== ==========================================
Loadpicturesource. asp
========================================================== ==========================================
<! -- # Include file = "conn. asp" -->
<%
Response. charset = "gb2312"
Dim picturesrc, picturealt, returnvalue
Picturesrc = request ("picturesrc ")
Picturealt = request ("picturealt ")
If picturesrc <> "" then
'Load the image address
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open "select * From pictureset where picname = 'homepage image' order by updatedate DESC", Conn, 3,3
For I = 1 to Rs. recordcount
If I = 1 then
Returnvalue = RS ("picpath ")
Else
Returnvalue = returnvalue & "|" & RS ("picpath ")
End if
Rs. movenext
Next
Elseif picturealt <> "" then
'Load the image description
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open "select * From pictureset where picname = 'homepage image' order by updatedate DESC", Conn, 3,3
For I = 1 to Rs. recordcount
If I = 1 then
Returnvalue = RS ("pictitle ")
Else
Returnvalue = returnvalue & "|" & RS ("pictitle ")
End if
Rs. movenext
Next
End if
Rs. Close
Conn. Close
Set rs = nothing
Set conn = nothing
Response. Write returnvalue
%>
========================================================== ==========================================
Conn. asp
========================================================== ==========================================
<%
Dim Conn, connstr
Connstr = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & server. mappath (".") & "/site. mdb; persist Security info = false"
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open connstr
%>
========================================================== ==========================================
Site. MDB
========================================================== ==========================================
Create Table pictureset
(
Id int identity,
Picname varchar (20 ),
Picpath varchar (50 ),
Pictitle varchar (50 ),
Updatedate datetime
)
Insert into pictureset (picname, picpath, pictitle, updatedate) values ('homepage image', './picturesource/autodisplay_1.jpg', 'image description', '2017-06-17 ')
Insert into pictureset (picname, picpath, pictitle, updatedate) values ('homepage image', './picturesource/autodisplay_2.jpg', 'image description', '2017-06-17 ')
Insert into pictureset (picname, picpath, pictitle, updatedate) values ('homepage image', './picturesource/autodisplay_3.jpg', 'image description', '2017-06-17 ')
Insert into pictureset (picname, picpath, pictitle, updatedate) values ('homepage image', './picturesource/autodisplay_4.jpg', 'image description', '2017-06-17 ')
Insert into pictureset (picname, picpath, pictitle, updatedate) values ('homepage image', './picturesource/autodisplay_5.jpg', 'image description', '2017-06-17 ')