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

📄 0120.htm

📁 ASP教程宝典 书籍语言: 简体中文 书籍类型: 网络编程 授权方式: 免费软件 书籍大小: 500 KB
💻 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>写文件</strong></big></p>

<div align="right">---(文/甘冀平)</div>

假设你想创建一个简单的留言簿,你可以建立一个数据库,在其中存储用户的信息。然而,如果并不需要数据库的强大功能,使用FSO来存储信息将节省你的时间和金钱。并且,一些ISP也许限制了web上的数据库应用。假设你在一个表单中收集了一些用户信息,这里是一个简单表单HTML代码:<br>
&lt; html&gt;<br>
&lt; body&gt;<br>
&lt; form action=&quot;formhandler.asp&quot; method=&quot;post&quot;&gt;<br>
&lt; input type=&quot;text&quot; size=&quot;10&quot; name=&quot;username&quot;&gt;<br>
&lt; input type=&quot;text&quot; size=&quot;10&quot; name=&quot;homepage&quot;&gt;<br>
&lt; input type=&quot;text&quot; size=&quot;10&quot; name=&quot;Email&quot;&gt;<br>
&lt; /form&gt;<br>
&lt; /body&gt;<br>
&lt; /html&gt;<br>
再看看formhandler.asp中处理表单的代码:<br>
&lt; %<br>
' Get form info<br>
strName = Request.Form(&quot;username&quot;)<br>
strHomePage = Request.Form(&quot;homepage&quot;)<br>
strEmail = Request.Form(&quot;Email&quot;)<br>
<br>
' create the fso object<br>
Set fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)<br>
<br>
   迄今为止,还没有新鲜的东西,无非是获取表单域的值并且赋值到变量。下面出现了有趣的部分 - 写文件:<br>
<br>
path = &quot;c: emp est.txt&quot;<br>
ForReading = 1, ForWriting = 2, ForAppending = 3<br>
<br>
' open the file<br>
set file = fso.opentextfile(path, ForAppending, TRUE)<br>
<br>
' write the info to the file<br>
file.write(strName) &amp; vbcrlf<br>
file.write(strHomePage) &amp; vbcrlf<br>
file.write(strEmail) &amp; vbcrlf<br>
<br>
' close and clean up<br>
file.close<br>
set file = nothing<br>
set fso = nothing<br>
<br>
<br>
   回想一下,OpenTextFile方法返回一个TextStream对象,它是FSO模型中的另外一个对象。TextStream对象揭示了操作文件内容的方法,比如写、读一行、跳过一行。VB常量vbcrlf产生一个换行符。<br>
<br>
  在OpentextFile的命令参数中定义了TRUE,这就告诉了系统,如果文件不存在,就创建它。如果文件不存在,并且没有定义TRUE参数,就会出错。<br>
现在转到目录c: emp,打开test.txt,你可以看到如下的信息:<br>
<br>
User's name<br>
User's home page<br>
User's email<br>
<br>
当然,这些单词可以被输入在表单中的任何内容所替换。

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

⌨️ 快捷键说明

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