


版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、實(shí)驗(yàn)2:內(nèi)置對象、Cookie及JavaBean實(shí)驗(yàn)一、實(shí)驗(yàn)?zāi)康模豪斫鈱ο蟾拍?,掌?application、session等對象的根本使用方法。理解Cookie概念,掌握Cookie的根本使用方法。理解JavaBear概念,掌握J(rèn)avaBean的根本使用方法。二、實(shí)驗(yàn)要求:使用開發(fā)工具Eclipse編程。編寫程序完成以下實(shí)驗(yàn)內(nèi)容并上交實(shí)驗(yàn)報(bào)告三、實(shí)驗(yàn)內(nèi)容:1、 編寫一個簡單的網(wǎng)上商店,用application對象存放網(wǎng)上的商品清單和庫存量,用session對象存放用戶的購置信息用戶名、商品名及購置數(shù)量,然后利用這些信息給用戶結(jié)賬。2、 利用Cookie實(shí)現(xiàn)用戶的自動登錄功能。其中,要求在登錄
2、頁面中通過對Cookie有效 期的設(shè)置來保存用戶的信息。3、 用JavaBean和JSP設(shè)計(jì)一個某教育機(jī)構(gòu)的簡易在線報(bào)名子系統(tǒng)。要求將表單輸入的信 息通過JSP向 JavaBean設(shè)置屬性,并通過JSP將獲取屬性返回給客戶端。四、實(shí)驗(yàn)過程中遇到的問題及解決手段:描述實(shí)驗(yàn)過程中遇到的問題并盡量提供解決的方法。五、參考源代碼:1網(wǎng)上商店:登陸.jsp :<%©page cantentTyp"test/htjiil. chaiset=g2312'%>+'body?"<farinJiL8tlicid="post" ac
3、tion= "applicationinput type-text"" n3ns= * use mame" /pVp align=J>centerxr!忌'碼:tinpirt typ8=assvorname= assvor/p>ali匚&玖丈已工"?吁11丈 type=,tf subnit name submit* "wahie="提交"2input typfi='*,reset" najne=,lfcancel id=cancftl,f valut=|5>/f
4、OXJK*1/body)1</html4-116 求.V矚p郵e contentlype"text/htBljchaxset=jt231 曠盼十xe-questi. setChaztexEnc ding (gb2312)3<%Iint al=30,32=25 a3=40; *double pl=48. 00,00, p3=45. 0O>String計(jì)算機(jī)網(wǎng)絡(luò):S2=*J5PS序設(shè)計(jì):裁二=+程序設(shè)計(jì)"一<htoalX<body»forni aiethod=post act ion-session,<tableX<tr al
5、ign=*center>.商品名</th><th>價格/元</th><th>庫存量</th><th>購置數(shù)量</th<tr align-left1*<th><Vsl%></thX<td><%=p 1V</td><td><ka 1%></1d><td><input type=*texttf namenunl*va 1 u 已二></rdX</trX<tr aligti=*
6、le£tffX<ThXVs2%X/th><td><iFp2%></td><td><%=a2%></1d><td>< input type二光ext" name=*num2'value=*0#X/Td>.</trX<tr align=laftX <thX*=a3%X/th>.<td><<V閃弔?。tdXtdX頤厲3吊JhdXMXinrHLt typetext* narne=dTmiin3" value=&
7、quot;0*X/TdX<td><input type"submit* naiue=*submit" value='交</irXVtableK塔application, set At tributes 1:.application. setAttributes2):.spplicat ion. set Al tribute Cs3*n s3) :.application. setAttribute 7pP, pl):.日 ppi i® ion. set At tribute <"*p2*,卩 2) “applicat
8、ion. stAttrihute(*p3, p3):.String iisernamerequest getParameterCusername');session, set Attribute ("uernaine, username)弗4</forinX<AodyX< At mlXsession, jspipage contentTypc-text/html;charaet-gb2312"%>.<html><body><p>® ij 1 <.'i -session . '
9、jet At tribute MLisei M ) ></p><Lr> .CpA您購置的商品如下:</p><br>Object idl-application.getAttribute"si")Objec 七 id2=app:l ication. get At tribute ("32")門 Object id3application.geLAttribute hs3*)Object strl=application.get赳VtributE"pl");< double gl
10、=Ecjube . pa rseDouble (st r 1, t oStr irg (); Object str 2=application * get Attribute (*rp2H );. double g2=Double * parseDouble(str2 * to5tting O;Object str3=applicatian . getAttrlbute *fp3M) double g3-Double .口注上甘總Doub丄電.5! ir r i nq nnml = request * get Parameter "numl")String num2=r e
11、qu.es t * get Parameter (nnum2")String num 3-request * get Parameter (nnum3,T)s e a 3 i on * set At t ribute ( "rrnnil" f num 1); sey jion £GlAt.匕丄丄butx (, nuni2); session setAtt rit*ucennrnaj 卜Object nil=5es3ion getJVttLiribut巳("numl *) ; + in七 nl=Integer parselnt(ml * toSt
12、ring();tib ject m2=£e£Bion.getAttribute (*口口泌丹):int n2=Integer»parseInt(m2.toString();-Ob j ect m3i=se£8ion. getAttr ibute (numZ?*);int nJ"Integer«parseInt(m3.toString()if n空=0"out. print In (idl .toS tring (| +h, " + 恪為:" + strl ,toString() +" "
13、;+"W買數(shù)量;B+ml. toStringO +n<br>")else(out»printIn();)if(n21=0 卜out. print In (id2 . toS tring ) + " 十 ffr 格為:M+ str2 . LoS bring () "+*購置數(shù)雖< "+m2-toStiring()+n<br>");.)else(out println ();+if (n31=0) +ont_pr±nt.ln (id3. toS亡ring () + ""
14、十審/匸格 Zl: Ir+str3 . toString () x + " 嚴(yán)購置數(shù)量* « m3 ttostring (-J else (out .print 丄ri O ; ;+%X弋"您需要支付的急金額為:<%=gl*nl+g2*n2+g3*n3%>x;</pX</bodyX</htmlx2.利用實(shí)現(xiàn)用戶的自動登錄功能:(joDkie jsp;<%pagc contentTypt?-" text/html; charsct-gb2312<body><form name=T,fonnl1T met
15、hod"po3tn action-"口窈ingCookiu<p 耳丄 ign=,1 ceriterp>.<iriput type=ntzextf, nHme=flusernarrLe 1px/p>-<p allgn=Hcenter<input type=t1ja9swordi<nc3me=*,pas5worri,></p><p aligns "center11 xLuput type = "3 ubcni tn Ddme=lf aubmi t'* *己1口呂="扌是.交
16、 &nbap; <input typc = *re3ct,r name11 cancle" value=*®(S</f onn></body></htniL>.usingCcokie. jsp:-<&page contentTypuu、' text /html ;char3et=gb2312 n*i><£reques t, setCharac ter Encoding (11gb2312't);<body>nString strnAfne-L
17、equeat *g&tParatneQ&r ('*username,f)String strword-request .gEtFaraniElieT ( "pasm科oud") rCookie nameCookie=new Cookie (rTnawfiT, strnme);-nameCookie . setMaixAQe f 10*60);Cookie wordcookie-new Cookie (thword1h, strword);wordCookie SEtMaxAg巳 f 10*60) ;審response.addCookie(nameCo
18、okie;response.addCook±ewordCookiereaponaesendRedirect(response.j spv);-</bodyX</html> vresponse.j sp:.<%(?page contentType=1'text/htmL;charset=gb2312*%><htmlx<body>iCp>歡送您! </p>-<%KCookie cook ies=requst * get Cook:es();if(cookies=nall.out .print (nSWCoo)
19、cien);-else-for(int i-0;i<cookie3» Length;i + + )(i f (cookies (i ,getName () .equals < ,rname,1) out.pt int (cookies ,getValue () ; + 卜%X</body>.</html»3在線報(bào)名子系統(tǒng);+showinfo.jsp:<%page cartentType="text/html; char set=gb2312n%>.<%request * eetCharacterEncoding (N
20、gb2312,f);令.<body>-< j sp:UEeBean id=:Muser M scopes1'session+l class=1*tt?s t. show*/>.<jsp:setProperty name-"user° property11* M/><%if(request,getParameter("nam巳")=null)告>><form name='*formlH method-*postN ax:t'*x <tablex<tr>+v
21、th>姓名* </thxtdxinput type=1*text* name= '*nameH></td>-</tirX<tr>.身份證號碼:</thxtd><input type-1*text11 rL&me='*number11 ></tdx</cr><trx年齡:</tlixtdxlnput type ''text'" name- "'agex/Ld>.<tr>.<th>性別;<
22、;/th><七dAUinput type="radioT, name='Tsexu value=,TMale,1>® <input type=Hradio1* name=Hsex'* vaXue = "Fernale11 >it</td>+</tr><tr>-t且?Vinput: type=11 checkbox" name=,*habit'Fvaluer'* read* >§45<input type11 checkbox1* nam
23、e"habit" value= Nbaskstball">E-<input type=,rcheckboxn name = ,1 habitM value=Hswijn'ijr< input type=11 checkbox '* name-11 habit* value3,lmu3i </td>.</tr><t r>.<td><input type=Hsubmit11 nanne=t,submit11 value=*'<input typenreset"
24、; name"rese七"value</tr></tabl e>.< / f o rmX<%else(%>姓名半 <=u3er * getName () %><brX身ftH正號百馬:<%=user, getNumber ) ><br> 年舲】<%=user,getAge () %><br>r f生 SU: <% = user gets ex ( %Xbr> 興極:<%user. get Hobby () %>.</bodyXshow, java:package test;-public class show private St ring name,number,sex,age,hobby; private String L J habit;-public void setName(String
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二手商務(wù)車買賣合同范例
- 醫(yī)學(xué)大數(shù)據(jù)的隱私保護(hù)與挖掘技術(shù)
- AI技術(shù)在不同行業(yè)中的社會接受度差異分析及對策建議
- 醫(yī)療行業(yè)中的區(qū)塊鏈去中心化應(yīng)用案例分享
- 乙方軟裝合同范例
- 從醫(yī)學(xué)角度看多學(xué)科協(xié)同如何助陣糖尿病防治
- 醫(yī)療大數(shù)據(jù)在患者管理與服務(wù)優(yōu)化中的應(yīng)用
- 醫(yī)療設(shè)備與技術(shù)的安全質(zhì)量管理探討
- 醫(yī)療器械行業(yè)的技術(shù)創(chuàng)新與GMP規(guī)范
- 醫(yī)療事故倫理責(zé)任界定及案例分析
- 2025年保密觀知識競賽題庫附答案(黃金題型)含答案詳解
- 市政道路交通導(dǎo)改方案
- 營養(yǎng)知識教學(xué)課件
- 美容行業(yè)皮膚知識課件
- GB/T 1040.1-2025塑料拉伸性能的測定第1部分:總則
- 赤峰市2025屆高三年級4?20模擬考試語文試卷(含答案)
- 2025-2030中國傳染病體外診斷行業(yè)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報(bào)告
- 中央2025年西部戰(zhàn)區(qū)專業(yè)技能崗位文職人員公開招考筆試歷年參考題庫附帶答案詳解
- 低阻抗條件下構(gòu)網(wǎng)型變流器多機(jī)系統(tǒng)的建模與穩(wěn)定性分析
- (廣東二模)2025年廣東省高三高考模擬測試(二)語文試卷(含答案解析)
- 湖北省武漢市2025屆高中畢業(yè)生四月調(diào)研考試歷史試題及答案(武漢四調(diào))
評論
0/150
提交評論