Web程序设计实验指导?116 - 百度文库 ر

//ʵʹӦݿеûȽ if (txtName.Text == \ {

lblName.Text = \Ǹûѱռã\ } else {

lblName.Text = \ϲûã\ } }

Web鿴Ч

ʵ HTTPӦ״̬

һʵĿ

(1) HttpRequestӦá (2) HttpResponseӦá (3) տҳύӦá

(4)CookieSessionApplicationProfileӦ

.ʵݼҪ

1.Ʋʵһ Ҫ£

(1) ҳЧͼ4-1~ͼ4-4ʾ (2) ûϢ洢ڶάС (3) ͼ4-2~ͼ4-4ʹÿܼ

(4) HttpResponseSessionApplicationӦá

ͼ4-1 ҡЧ1 ͼ4-2 ҡЧ2 ͼ4-3 ҡЧ3 ͼ4-4 ҡЧ4

2.Ʋʵͬһ׵Ĺﳵ Ҫ£

(1)ҳЧͼ4-5ʾ

ͼ4-5 ﳵЧ1

(2) ѡӦ롰빺ﳵťɿѡijͼ4-6ʾ

ͼ4-6 ﳵЧ2

(3) ͼ4-7ʾչﳵťﳵеijϢʾûѡκγʾϢ

ͼ4-7 ﳵЧ3

.ʵ鲽

1. Ʋʵһ׵ 1½վ

½һվWebChatLogin.aspxWebChatDisplay.aspxWebSendMessage.aspxHTMLҳChat.htmȫӦóGlobal.asaxChatLogin.aspxû¼ChatDisplay.aspxʾϢSendMessage.aspxڷϢChat.htmÿҳGlobal.asaxڴ洢Application_Start¼롣

2ChatLogin.aspx

ͼ4-8ʾͼһڲֵı˵Ϣ2TextBoxؼ2RequiredFieldValidatorؼ1ButtonؼʵؼĴСλá

ChatLogin.aspxиؼ4-1ʾ

ͼ4-8 ƽ棨1 4-1 ؼñ

ؼ ֵ ˵ TextBox RequiredFieldValidator ID ID txtName rfvName ûıı ֤ؼı ControlToValidate Text TextBox ID TextMode RequiredFieldValidator ID txtName * txtPassword Password rfvPassword ֤ûı ֤ЧʱʾĴϢ 롱ıı á롱ıΪģʽ ֤ؼı ControlToValidate Text Button ID Text 3дChatLogin.aspx¼

txtPassword * btnLogin ¼ ֤롱ı ֤ЧʱʾĴϢ ¼ťı ¼ťʾı ¼һû飬£

//userû롣ʵʹӦݿлȡ

string[,] user = { { \\, \ }, { \\, \ }, { \\, \ } };

Web״ʱִеĴ£

//㶨λڡûı txtName.Focus();

ť btnLoginʱִе¼£

protected void btnLogin_Click(object sender, EventArgs e) {

//userѭƥû for (int i = 0; i <= 2; i++) {

if (txtName.Text == user[i, 0] && txtPassword.Text == user[i, 1]) //ƥɹ

{

//ûSessionuser Session[\] = user[i, 0]; //ضҳ

Response.Redirect(\); } }

//userҲƥûû󣡡ʾϢ Response.Write(\û');\);

}

4ChatDisplay.aspx

ͼһLabelؼIDֵΪlblMsgлԴͼǩ֮Ĵ룬ڿChatDisplay.aspxÿ4sԶˢһΡ

5дChatDisplay.aspx¼ Web״ʱִеĴ£

protected void Page_Load(object sender, EventArgs e) {

lblMsg.Text = Application[\].ToString();

}

6SendMessage.aspx

ͼ4-9ʾͼ1Labelؼ1TextBoxؼ1ButtonؼʵؼĴСλá

ͼ4-9 ƽ棨2

SendMessage.aspxиؼ4-2ʾ

4-2 ؼñ

ؼ Label ID ֵ lblName ˵ ʾϢLabelؼ TextBox ID TextMode txtMessage MultiLine Ϣıı áϢıΪģʽ Button ID Text 7дSendMessage.aspx¼ Web״ʱִеĴ£

protected void Page_Load(object sender, EventArgs e) {

lblName.Text = \ˣ\ + Session[\]; if (!IsPostBack) {

Application[\] += Session[\] + \
\;

btnSend ͡ťı ͡ťʾı