收藏 分销(赏)

网络管理复习资料.doc

上传人:仙人****88 文档编号:11324767 上传时间:2025-07-17 格式:DOC 页数:6 大小:250.50KB 下载积分:10 金币
下载 相关 举报
网络管理复习资料.doc_第1页
第1页 / 共6页
网络管理复习资料.doc_第2页
第2页 / 共6页


点击查看更多>>
资源描述
<p>第六讲 主要内容 复习前一节内容 面向对象基础-类与对象/构造方法 新的内容 第4章 ASP.NET 2.0页面基本对象 7个 一. Application对象 Application对象属于服务器对象,用来保存页面中的一些公用数据。通常用于创建网页计数器。 定义属性:Application[“属性名”] Application[“name”]=”方房” 区别于String &nbsp;name=”方房” [例1](考题): 13、创建一个web窗体---Test23.aspx,利用Application对象统计网页访问人数。程序界面如图13所示。 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;图 13 1、 在设计窗体中拖入试题中所需的label控件(注意他们的id属性)。 2、“label”按钮的命令如下: protected void Page_Load(object sender, EventArgs e) &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp;int num = 0; &nbsp; &nbsp; &nbsp; &nbsp;Application.Lock(); &nbsp; &nbsp; &nbsp; &nbsp;if (Convert .ToInt16 ( Application[&quot;count&quot;]) == 0) &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Application[&quot;count&quot;] = 1; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;num =Convert .ToInt16 ( Application[&quot;count&quot;]); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Application[&quot;count&quot;] = num + 1; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp;this.Label1 .Text =Application [&quot;count&quot;].ToString (); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} 2. Request对象:从客户端得到数据 常用方法有request.form[ ] 和request.querystring[]。 1) Form[] 方法,用来获取客户以post方式提交的数据。 2) Querystring[]方法,用来获取客户以get方式提交的数据。 Response对象:向浏览器输出信息 常用方法有response.write()。 [例2](考题): 14、创建两个web窗体---Test14.html和Test14.aspx,在Test14.html中使用GET和POST方法提交用户名name和地址address,在Test14.aspx中获取该信息并显示。程序界面如图14所示。 图 14 1、 创建一个html页面test14.htm (以post方式为例) 这样创建:1)拉入3个控件input(text1)、input(text2)和input(submit1),给3个控件命名,也就在属性窗口中分别设置name属性值为user、address、submit。 2)在源代码视图中,在标签中输入</p><form></form><p>,然后设置form的method属性为post,action属性为test24.aspx。 3)再到设计视图中双击submit控件,使之调用onclick函数。即可完成。 2、创建一个test14.aspx &nbsp; public partial class Test24 : System.Web.UI.Page { &nbsp; &nbsp;protected void Page_Load(object sender, EventArgs e) &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp;string name = Request.Form[&quot;user&quot;]; &nbsp; &nbsp; &nbsp; &nbsp;string address = Request.Form[&quot;address&quot;]; &nbsp; &nbsp; &nbsp; &nbsp;Response.Write(&quot;用户名为:&quot;+name+&quot;<br/>&quot;); &nbsp; &nbsp; &nbsp; &nbsp;Response.Write(&quot;地址为:&quot;+address+&quot;<br/>&quot;); &nbsp; &nbsp;} } 3. 文件上传控件fileupload:把客户机器上的文件上传到服务器的某个目录下。P89 FileUpload 控件显示一个文本框控件和一个浏览按钮,使用户可以选择客户端上的文件并将它上载到 Web 服务器。用户通过在控件的文本框中输入本地计算机上文件的完整路径(例如,C:\MyFiles\TestFile.txt)来指定要上载的文件。用户也可以通过单击“浏览”按钮,然后在“选择文件”对话框中定位文件来选择文件。 &nbsp;用户选择要上载的文件后,FileUpload 控件不会自动将该文件保存到服务器。您必须显式提供一个控件或机制,使用户能提交指定的文件。例如,可以提供一个按钮,用户单击它即可上载文件。为保存指定文件所写的代码应调用 SaveAs 方法,该方法将文件内容保存到服务器上的指定路径。通常,在引发回发到服务器的事件的事件处理方法中调用 SaveAs 方法。 FileUpload控件的常用属性,都是只读的属性。 属性 数据类型 说明 FileContent Stream 获取指定上传文件的Stream对象 FileName String 获取上传文件在客户端的文件名称 HasFile Bool 获取一个布尔值,用于表示FileUpload控件是否已经包含一个文件 PostedFile HttpPostedFile 获取一个与上传文件相关的HttpPostedFile对象,使用该对象可以获取上传文件的相关属性 例3 15、创建一个web窗体---Test15.aspx,实现文件上传,将文件上传到服务器根目录下。程序界面如图15所示。 图 25 1、 在设计窗体中拖入试题中所需的控件(注意他们的id属性)。 2“确定”按钮的命令如下: protected void Button1_Click(object sender, EventArgs e) &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp;if(this.FileUpload1.HasFile !=null)// HasFile 属性来验证 FileUpload 控件确实包含文件 &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string strdir = this.FileUpload1.PostedFile.FileName;// 调用FileUpload控件的FileName属性,获得文件名 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int pos = strdir.LastIndexOf(&quot;\\&quot;);//lastIndexOf() 方法可返回一个指定的字符串值最后出现的位置。LastIndexOf()方法返回一个整数值。 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string filename = strdir.Substring(pos); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string strpath = Server.MapPath(&quot;.&quot;) + filename; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.FileUpload1.PostedFile.SaveAs(strpath );// SaveAs 方法文件内容保存到服务器上的指定路径 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.Write(&quot;上传成功!&quot;); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp;} [练习] 参看书P60 2、将上题例2以get方式完成。 【思考】:</p>
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 考试专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服