Response.ContentType
Response.ContentType 是用来控制输出的文件类型的。
服务器送给客户端的数据包类型可以是text/html文本,也可以是gif/jpeg图形文件,所以每次传输前,我们都必须告知客户端将要传输的文件类型,一般默认情况下为“Text/Html”类型。
1
<% Response.ContentType = "text/HTML" %>
2
<% Response.ContentType = "image/GIF" %>
3
<% Response.ContentType = "image/JPEG" %>
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
用于作为文本内容返回而不是已解释的 HTML 语句
Response.ContentType = "text/plain"
1
<%
2
Response.ContentType = "text/plain"
3
Response.write(now()&"会被执行么?")
4
%>
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
你可以注意到:页面提供下载,页面中的ASP内容被解释执行了的程序文件以XLS文件被提供下载
Response.ContentType = "application/vnd.ms-excel"
1
<%
2
Response.ContentType = "application/vnd.ms-excel"
3
Response.write("本页面调试会出现下载对话框提供下载,保存类型为XLS")
4
%>
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
实现歌曲连续播放
response.ContentType="audio/x-pn-realaudio"
1
<%
2
Dim ramstr
3
ramstr=""
4
Set rs=Server.CreateObject("Adodb.RecordSet")
5
sql="XXXXXXXXXXX"
6
rs.open sql,conn,1,3 'conn已定义
7
Do While Not rs.eof
8
ramstr=ramstr&rs("url")&vbCrLf
9
rs.MoveNext
10
loop
11
rs.Close
12
Response.ContentType="audio/x-pn-realaudio"
13
'response.ContentType="audio/x-mpegurl"
14
Response.Write ramstr
15
%>
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/None.gif)
11
![](/Images/OutliningIndicators/None.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/None.gif)
14
![](/Images/OutliningIndicators/None.gif)
15
![](/Images/OutliningIndicators/None.gif)
response.write 输出的时候,由于定义了response.ContentType 所以输出歌曲地址的时候会自动调用符合相应格式的软件来播放歌曲,不过前提是播放歌曲的软件必须先安装的。response.write 输出的时候,由于定义了response.ContentType 所以输出歌曲地址的时候会自动调用符合相应格式的软件来播放歌曲,不过前提是播放歌曲的软件必须先安装的。
<% Response.charset="GB2312" %>