📄 代码清单3-17.htm
字号:
style='mso-spacerun:yes'>
</span>}<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#011<span
style='mso-spacerun:yes'> </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#012<span
style='mso-spacerun:yes'> </span>//</span><span
style='font-size:9.0pt;font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>向服务器提交验证请求</span><span lang=EN-US
style='font-size:9.0pt'><o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#013<span
style='mso-spacerun:yes'>
</span>function getSessionId(){<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#014<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span>createXMLHttpRequest();<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#015<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:1'> </span>var timestamp = new
Date().getTime();<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#016<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:1'> </span>var
url="/ajaxstudy/third/httpSessionServer.jsp?name=";<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#017<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:1'> </span>url +=
document.getElementById('name').value + "&password=";<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#018<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:1'> </span>url +=
document.getElementById('password').value +
"&timestamp="+timestamp;<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#019<span
style='mso-spacerun:yes'>
</span><span style='mso-tab-count:1'> </span>xmlHttp.open("GET",url,true);<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#020<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span>xmlHttp.onreadystatechange
= setSession;<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#021<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span>xmlHttp.send(null);<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#022<span
style='mso-spacerun:yes'> </span><span
style='mso-spacerun:yes'> </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#023<span
style='mso-spacerun:yes'> </span>//</span><span
style='font-size:9.0pt;font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>判断并保存服务器返回会话</span><span lang=EN-US
style='font-size:9.0pt'>ID<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#024<span
style='mso-spacerun:yes'>
</span>function setSession(){<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#025<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span>if (xmlHttp.readyState
== 4) { <o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#026<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:3'> </span>if
(xmlHttp.status == 200) { <o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#027<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:4'> </span>var
sessionid = xmlHttp.responseText;<span style='mso-spacerun:yes'> </span><o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#028<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:4'> </span>var
frame = getIFrameDoc('httpSessionFrame'); <o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#029<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:4'> </span>if(sessionid.match(/null/)){<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#030<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:5'> </span>alert('</span><span
style='font-size:9.0pt;font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>用户名或密码输入不正确</span><span lang=EN-US
style='font-size:9.0pt'>');<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#031<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:5'> </span>frame.body.innerHTML="";<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#032<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:4'> </span>}else{<span
style='mso-tab-count:4'> </span><o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#033<span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
4'> </span>frame.body.innerHTML="<input
type='text' id='sessionId' value="+sessionid+">"; <o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#034<span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
1'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
4'> </span>alert('</span><span
style='font-size:9.0pt;font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>用户会话</span><span lang=EN-US
style='font-size:9.0pt'>ID</span><span style='font-size:9.0pt;font-family:宋体;
mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman"'>保存成功</span><span
lang=EN-US style='font-size:9.0pt'>'); <o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#035<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:3'> </span><span
style='mso-spacerun:yes'> </span>}<span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:2'> </span><span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
4'> </span><o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#036<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:3'> </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#037<span
style='mso-spacerun:yes'> </span><span
style='mso-tab-count:1'> </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#038<span
style='mso-spacerun:yes'> </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#039<span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
2'> </span>//</span><span
style='font-size:9.0pt;font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>得到页面内隐藏的</span><span lang=EN-US
style='font-size:9.0pt'>IFrame<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#040<span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
1'> </span><span
style='mso-spacerun:yes'> </span>function getIFrameDoc(id) {<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#041<span
style='mso-spacerun:yes'> </span><span style='mso-tab-count:
1'> </span><span
style='mso-spacerun:yes'> </span>var frame = <o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:18.0pt;background:#E6E6E6'><span
lang=EN-US style='font-size:9.0pt'>#042<span
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -