Data | database----Active Server Pages (ASP) is a server-side scripting environment that you can use to create dynamic Web pages or build powerful Web applications, and ASPs make these jobs easy. ASP pages are files that include HTML markup, text, and script commands. ASP pages can invoke ActiveX components to perform tasks, such as connecting to a database or doing business calculations. With ASP, you can add interactivity to your Web pages or form an entire Web application with HTML pages that use HTML pages as the interface for your customers.
----When we use ASP for database-related development, we often deal with the graphics stored in the database. Typically, a graphic is stored in a field in a blob (Binary Large Object) type in the database. This article describes how to access graphics in a database in ASP.
----Most browsers support graphics files in GIF and JPEG format, where IE supports GIF, JPEG, BMP three formats, and NC supports GIF and JPEG only. When the picture is displayed, the browser sends a request to the server, and the server sets the MIME type in the HTTP header to Image/gif or image/jpeg when the graphic is transferred to the browser, so the browser knows what format to display the graphics in.
----Understand the truth, we know how to handle graphics in ASP. The following is a simple example of a GIF format with a file named showgif.asp:
<%@ language=vbscript% >
<%
' Clear header information
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear
' Change contenttype notify browser to send GIF
Response.ContentType = "Image/gif"
' The following is the operation of the database
Set conn = Server.CreateObject
("ADODB.") Connection ")
Conn. Open "Database", "sa", "password"
Set rs = cn. Execute ("Select picture
From pic WHERE pic_id= ' 007 ')
' Return graphic
Response.BinaryWrite RS ("logo")
Response.End
% >
----The function of this example is simple, just return a graphic. But in practical applications, we often encounter situations in which graphics and text are returned at the same time. At this time, to the HTTP header in the MIME type set to Text/html, otherwise the text is not obvious. So, we can use an HTML file plus an ASP file to implement. HTML files can be written like this:
< HTML >
< head >< TITLE > display text and Images </title >< BODY >
Here is the text, below is the graphics < BR >
< IMG src= "showgif.asp" >
</body >
The key to----example is this < IMG src= "showgif.asp", which showgif.asp the returned content as a graphic.
----The approach described above is not only useful for graphics, but also for other binary data. For example, you can display a Word document by setting the MIME type to Application/msword.
----The examples in this article are run through the NT 4.0 + IIS 4.0 + SQL Sever 7.0 Environment