ASP uses the Response property

zhaozj2021-02-08  243

---- I encountered such a problem when making a web page with ASP for a web page. In the previous MIS system, some Word files are saved in the form of a word-definition in the database. Now the user requests me to use these words with ASP. The file data is removed from the database and is displayed in the web page. Start I naturally think of creating a temporary file on the server, then add a link to this temporary file, but this method will greatly increase the burden of the server, and how to ensure the specific client to use the temporary The file is not overwritten by the files used by other clients, how to delete files after the file is transferred to the user, these problems are actually difficult to solve. So is there a better way?

---- To this end, I took a closer look at the ASP's reference, and found that the Response object has a property called ContentType, which defines the MIME type of the server to send to the client content. MIME full name Multipurpose Internet Mail Extensions, Multi-function Internet mail extension. We know that we sometimes point the hyperlink to a Word or Excel file during web programming, and the browser automatically calls the corresponding method to open this file when the user clicks on this link. The reason why it can do is because the user machine will be installed on the browser to register the corresponding MIME resource type. For example, the MIME type of the Word file is Application / Msword (the former is the MIME type, the latter is a mime subclass), the MIME resource type of the Excel file is Application / Msexcel. In fact, all resources that the browser can process have corresponding MIME resource types, such as the MIME type of the HTML file is Text / HTML, the MIME type of the JPG file is image / jpg. In interaction with the server, the browser determines what kind of processing in accordance with the MIME type of the received data, opens it directly to the HTML, JPG and other file browsers, and the browser such as Word, Excel cannot be opened. The file calls the corresponding method to open. For files that are not marked MIME types, the browser speculates its type according to its extension and file content. If the browser can't guess, it will use it as an Application / OcTet-stream. To understand the MIME type of various files, please check in the Win98 My Computer -> View -> Folder option -> file type.

- - I am so moving, thinking that in the ASP, you can take the Word data in byte flow mode, then mark it as Application / Msword, and send it to the client, the client receives this resource After that, according to its MIME type, Word on the client (of course, the premise is that the client has installed Word, otherwise it will use it as an unrecognized resource, prompting the user to save, not open it). The test effect is very good, the method is simple and the speed is very fast, and the browser in IE5 uses the inline mode (similar to the OLE mode), the effect is better. The following is the program content.

---- Hypothesis Tab_Word, there are two fields in the table, one is an integer, name ID, unique identifier for Word data, another blob type, name word WordData, store Word data. Now display the content file content of the ID equal to 1 on the page, the ASP program is as follows:

<%

'Conn - Database connection created

'RS - Results Set

RS = conn.execute ("SELECT

WordData from tab_word where id = 1 ")

Response.contentType = "Application / Msword"

Response.writebinary (RS ("WordData"))

'Pay attention to the data in the result concentration directly with WriteBinary, do not use variables

'Receive this data, otherwise the system will report an error

%>

---- With a similar approach, many types of data such as Excel, BMP can also be handled. This program is tested in the following system: Server: NT IIS SQLServer client: Win98 IE5 or Netscape4.x

Dingbo Tao (98th Research on the Communication and Information College of Wuhan University)

转载请注明原文地址:https://www.9cbs.com/read-2374.html

New Post(0)