⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0150.htm

📁 asp教程宝典``还不错
💻 HTM
字号:
<html>

<head>
<title>新时代软件教程:操作系统 主页制作 服务器 设计软件 网络技术 编程语言 文字编辑</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
<!--
body, table {font-size: 9pt; font-family: 宋体}
a {text-decoration:none}
a:hover {color: red;text-decoration:underline}
.1  {background-color: rgb(245,245,245)}
-->
</style>
</head>
<p align="center"><script src="../../1.js"></script></a>
    <p align="center"><big><strong>关于ASP图象问题总结</strong></big></p>

<div align="right">---摘自《eNet学院》</div>

<pre>
如何处理ASP中的图象

在用ASP编程中,很多时侯要用到图象。对于单纯从数据库中处理一个图象,方法大家讲了很多,也不难,

可以看下面的代码:

这里假设你有个数据库名字叫:PUBS,在数据库中有一个叫:PUB_INFO的表,在表中有一个LOGO

的BLOB列。我们查出PUB_ID=0736的人的相片。

FILE: SHOWIMG.ASP

***************************************

&lt;%@ LANGUAGE="VBSCRIPT" %>

&lt;%

' Clear out the existing HTTP header information

Response.Expires = 0

Response.Buffer = TRUE

Response.Clear

' Change the HTTP header to reflect that an image is being passed.

Response.ContentType = "image/gif"

Set cn = Server.CreateObject("ADODB.Connection")

' The following open line assumes you have set up a System DataSource

' by the name of myDSN.

cn.Open "DSN=myDSN;UID=sa;PWD=;DATABASE=pubs"

Set rs = cn.Execute("SELECT logo FROM pub_info WHERE pub_id='0736'")

Response.BinaryWrite rs("logo")

Response.End

%>

*****************************************

执行这个ASP文件就可以看到你存在数据库中的图象了。

但如果是同时处理文字和图象就会有些困难了:-(

比如:一个企业的人员管理,后台数据库可以用SYBASE或SQL SERVER等。(我在这用SQL SERVER)当

你在企业内部需要用到BROWSE/SERVER方式,即用浏览器查看员工的个人信息时,就即要处理文字信息同时

还要用到关于图象的技巧。

问题在于你显示文字信息时HTML的HEAD中的CONTENT=“TEXT/HTML”,而显示图象则必须是

CONTENT=“IMAGE/GIF”或者是CONTENT=”IMAGE/JPEG“。因此你是无法只用一个ASP文件就把文字信息和

图象都处理完的,解决的办法是:用一个单独的ASP文件处理图象,然后在处理文字信息的ASP文件中调用

这个ASP文件。

在这给大家介绍一个我的解决方法,希望大家一起讨论:

环境:WINNT4.0 SQL SERVER IIS3.0

数据库名:RSDA

表名:RSDA_TABLE

目的:从RSDA_TABLE中查出ID=00001的人员的信息,包括姓名,年龄和照片

第一步:创建一个查询表单RSDA.HTM:

**********************************

&lt;html>

&lt;head>

&lt;/head>

&lt;body>

&lt;form method="POST" action="SEARCH.ASP">

&lt;p>请输入编号:&lt;input type="text" name="T1" size="20">&lt;input

type="submit" value="提交" name="B1">&lt;input type="reset" value="复原" name="B2">&lt;/p>

&lt;/form>

&lt;/body>

&lt;/html>

***********************************

第二步:建立SEARCH.ASP

***********************************

&lt;html>

&lt;head>

&lt;meta http-equiv="content-type" content="text/html;charset=gb2312">

&lt;title>查询结果&lt;/title>

&lt;/head>

&lt;body bgColor=Azure>

&lt;%

session("RSDA_ID")=Request.Form("T1") '这里我用了一个SESSION变量,是为了在处理图象的ASP文件中再次调用 

temp_id=session("RSDA_ID")

&lt;font size=4 color=OrangeRed> 查询结果:&lt;/font>

&lt;%set conntemp=server.createobject("adodb.connection")

conntemp.open "dsn=RSDA;uid=sa;pwd=SA"

set rstemp=conntemp.execute("select * from RSDA_TABLE where rsda='"&temp_id&"'")

%>

&lt;% 'put headings on the table of field names

nobody="对不起!在我们的数据库里没有您要找的资料!"%> '判断是否有这个人

&lt;%if rstemp.eof then %>

&lt;font size="5" color=OrangeRed> &lt;%Response.Write(nobody)%>&lt;/font>

&lt;%else%>

&lt;div align="center">

&lt;center>

&lt;table border="1" width="73%" height="399">

&lt;tr>

&lt;td width="21%" height="49" align="center">&lt;p align="center">姓 名&lt;/td>

&lt;td width="30%" height="49" align="center">

&lt;font size=4 color=OrangeRed>&lt;%=rstemp(0)%>&lt;/font>&lt;/td>

&lt;/td>

&lt;tr>

&lt;td width="21%" height="47">&lt;p align="center">年 龄&lt;/td>

&lt;td width="30%" height="47" align="center">

&lt;font size=4 color=OrangeRed>&lt;%=rstemp(0)%>&lt;/font>&lt;/td>

&lt;/tr>

&lt;tr>

&lt;td width="49%" height="146" rowspan="3" colspan="2">

&lt;img src="jpg.asp">&lt;/td> 'JPG.ASP就是我们将要建立的专门处理图象的ASP文件

&lt;/tr>

&lt;/table>

&lt;/center>&lt;/div>

rstemp.close

set rstemp=nothing

conntemp.close

set conntemp=nothing

%>

&lt;/BODY>

&lt;/HTML>

***********************************

第三步:建立处理图象的ASP文件。(JPG.ASP)

***********************************

&lt;%

Response.Expires = 0

Response.Buffer = TRUE

Response.Clear


' Open database

Set conntemp = Server.CreateObject("ADODB.Connection")

conntemp.open "dsn=RSDA;uid=sa;pwd=SA"

'change http header

Response.ContentType = "image/jpeg" ' or "IMAGE/GIF"


' Get picture


TEMP_ID=session("RSDA_ID")

Set Rs = conntemp.Execute("SELECT photo from RSDA_table where ID='"&TEMP_ID&"'")

Response.BinaryWrite Rs("photo")

Session.Abandon 

Response.End

%>

**********************************

这里主要就是用到了一个小技巧就是利用了一个SESSION变量来实现两次同条件查询。

大家如我上述只需少量改动,就可以实现一个页面既有文字又有图象了!
</pre>

  </table>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -