




已閱讀5頁(yè),還剩9頁(yè)未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
Struts1Struts11Struts1和Servlet的關(guān)系1創(chuàng)建第一個(gè)Struts1項(xiàng)目1例子1:3總結(jié)重點(diǎn):struts1的工作流程(基于MVC模式的)7一普通的Servlet的工作流程7二Structs1的工作流程(和上面的對(duì)比記憶)8Struts標(biāo)簽9Bean標(biāo)簽9html標(biāo)簽10logic標(biāo)簽(邏輯標(biāo)記)12i18n(國(guó)際化)13Struts1Struts1和Servlet的關(guān)系實(shí)體 - VOJsp+Javabean業(yè)務(wù)邏輯-daoJsp+Servlet+Javabean接收數(shù)據(jù)ActionForm跳轉(zhuǎn)ActionForward控制ActionServletActionForm和VO的區(qū)別:一樣的內(nèi)容,不一樣的作用ActionForm只接收前臺(tái)表單傳來的數(shù)據(jù)VO是conga后臺(tái)提取的數(shù)據(jù)向前臺(tái)傳遞創(chuàng)建第一個(gè)Struts1項(xiàng)目新建一個(gè)web項(xiàng)目,選擇1.4即可右鍵-MyEclipse-Add Struts Capacity-Struts控制文件的路徑TLD(標(biāo)簽)1)2):顯示信息3):邏輯標(biāo)簽struts-config.xml 擔(dān)任Controller的是ActionServlet,所有的客戶端請(qǐng)求都通過它來完成轉(zhuǎn)發(fā),必須在web.xml中配置: 注意:1)設(shè)定config參數(shù)的作用是設(shè)定struts-config.xml(包括了所有的Struts的相關(guān)請(qǐng)求轉(zhuǎn)發(fā)及一些資源設(shè)定)的文檔來源2)Servlet-mapping將所有以*.do結(jié)尾的請(qǐng)求將給ActionServlet來處理例子1:1) index.jsp 用戶名:密碼: 2) struts-config.xml3) UserFormpublic class UserForm extends ActionFormprivate String username;private String pwd;public String getUsername() return username;public void setUsername(String username) this.username = username;public String getPwd() return pwd;public void setPwd(String pwd) this.pwd = pwd;4) UserActionpublic class UserAction extends Action public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception /1.得到表單中方的數(shù)據(jù)UserForm userform = (UserForm) form;String username = userform.getUsername();String pwd = userform.getPwd();/2.往后臺(tái)傳數(shù)據(jù)System.out.println(username+=+pwd);boolean flag = UserDao.getInstance().findByUser(username, pwd);if(flag)return mapping.findForward(success);elsereturn mapping.findForward(error);5) UserDao/單例模式public class UserDao private static UserDao instance = new UserDao();private UserDao()public static UserDao getInstance()return instance;public boolean findByUser(String username,String pwd)return false;6)連接數(shù)據(jù)庫(kù)(DBConnection 和UserDao)public boolean findByUser(String username,String pwd)boolean flag = false;DBConnection db = new DBConnection();String sql = select username,password from users where username=? and password=?;try Connection conn = db.connection();PreparedStatement pst = conn.prepareStatement(sql);pst.setString(1, username);pst.setString(2, pwd);ResultSet rs = pst.executeQuery();if(rs.next()flag = true; catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return flag;7)獲取信息:在頁(yè)面上可以使用EL表達(dá)式8)在UserForm中新加入兩種方法:/和表單中按鈕的作用是一樣的public void reset(ActionMapping mapping, HttpServletRequest request) System.out.println(reset);/驗(yàn)證框架public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) System.out.println(驗(yàn)證框架);return super.validate(mapping, request);順序:先清空,再放值,再驗(yàn)證9)動(dòng)態(tài)獲取表單的數(shù)據(jù)struts-config.xml將原來的form-bean去掉將UserAction改為:public class UserAction extends Action public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception /1.得到表單中方的數(shù)據(jù)DynaActionForm userForm = (DynaActionForm) form;System.out.println(userForm.get(username)+*+userForm.get(pwd);String username = (String) userForm.get(username);String pwd = (String) userForm.get(pwd);/2.往后臺(tái)傳數(shù)據(jù)boolean flag = UserDao.getInstance().findByUser(username, pwd);if(flag)request.setAttribute(username, username);return mapping.findForward(success);elsereturn mapping.findForward(error);總結(jié)重點(diǎn):struts1的工作流程(基于MVC模式的)一普通的Servlet的工作流程1.web客戶端發(fā)送一個(gè)request到tomcat2.tomcat接受請(qǐng)求,3.new HttpServletRequest對(duì)象4.new HttpServletResponse 對(duì)象5.發(fā)送doGet/doPost到相應(yīng)的servlet6.servlet截取到相應(yīng)的URL7.根據(jù)URL找到相應(yīng)(文件/數(shù)據(jù))8.調(diào)用相應(yīng)的業(yè)務(wù)邏輯就是調(diào)用相應(yīng)的Dao9.對(duì)數(shù)據(jù)的操作10.返回給Dao一個(gè)結(jié)果11.將Dao返回的結(jié)果返回到相應(yīng)的servlet12.servlet會(huì)根據(jù)返回的結(jié)果找到跳轉(zhuǎn)的頁(yè)面13.在tomcat會(huì)根據(jù)結(jié)果生成頁(yè)面14.將頁(yè)面返回給web客戶端二Structs1的工作流程(和上面的對(duì)比記憶)Web客戶端ActionServlet1.requestStruts-config.xml文件Action業(yè)務(wù)邏輯控制器Model 業(yè)務(wù)邏輯Jsp1 web客戶端發(fā)送一個(gè)request到tomcat2 tomcat接受請(qǐng)求3 new HttpServletRequest對(duì)象4 new HttpServletResponse對(duì)象5 發(fā)送doGet/doPodt方法到相應(yīng)的ActionServlet6 ActionServlet會(huì)讀取struts-config.xml文件7 截取url信息8 根據(jù)url的配置信息,取得數(shù)據(jù)(從struts中的Action標(biāo)簽的內(nèi)容放到ActionMapping當(dāng)中)9 New ActionForm對(duì)象(作用:會(huì)收集表單數(shù)據(jù),進(jìn)行存?。?0 ActionServlet會(huì)取得表單數(shù)據(jù)11 New Action12 會(huì)執(zhí)行Actiion中的execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)13 從ActionForm中取得數(shù)據(jù)14 調(diào)用相應(yīng)的模型層15 返回?cái)?shù)據(jù)搭配Action16 通過ActionForward返回到ActionServlet17 通過forward到視圖層(jsp)生成jsp18 返回response到web客戶端Struts標(biāo)簽Bean標(biāo)簽標(biāo)簽頭在哪找到:struts包下的打開即寫成1) BeanActionpublic class BeanAction extends Actionpublic ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception request.setAttribute(hello, 測(cè)試一下);request.setAttribute(hello1, 測(cè)試一下);return mapping.findForward(show);2) struts-config.xml3) success.jsp 結(jié)果:其他標(biāo)簽:復(fù)制標(biāo)記顯示Bean屬性標(biāo)記 標(biāo)記 注意:filter為true是不支持html代碼html標(biāo)簽(只要是html就可以改成struts1的代碼)和相同說明:生成的結(jié)果取決于Struts應(yīng)用程序所位于的服務(wù)器的locale。如果你將應(yīng)用程序部署到一個(gè)不同locale的服務(wù)器,你不需要改變代碼,Locale會(huì)自動(dòng)調(diào)整 User Name: Password: 說明:html:form 相當(dāng)于form html:text 相當(dāng)于 html:submit 相當(dāng)于提交按鈕 focus 是光標(biāo)1) BeanActionpublic class BeanAction extends Actionpublic ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception UserForm user = (UserForm) form;user.setUsername(堂吉訶德);user.setPwd(123);request.setAttribute(user,user );return mapping.findForward(show);2) struts-config.xml3) success.jsp 用戶名:密 碼: 結(jié)果:其他標(biāo)簽:標(biāo)記 :(property: 元素名稱 ;size: 顯示的字?jǐn)?shù) ;value: 元素初值 ;redisplay: 是否顯示ActionForm的值)標(biāo)記標(biāo)記 標(biāo)記 標(biāo)記 標(biāo)記標(biāo)記標(biāo)記 標(biāo)記 標(biāo)簽 :(forward屬性:鏈接到一個(gè)global forward上;action屬性:鏈接到一個(gè)action mapping上;href屬性:這個(gè)鏈接會(huì)轉(zhuǎn)發(fā)給控制器,由控制器做決定;page屬性:一個(gè)相對(duì)的鏈接)標(biāo)簽 標(biāo)記 logic標(biāo)簽(邏輯標(biāo)記)1) BeanActionpublic class BeanAction extends Actionpublic ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception request.setAttribute(hello,null);List list = new ArrayList();request.setAttribute(list, list);String str = ;request.setAttribute(str, str);return mapping.findForward(show);2) success.jsp為空不為空為空不為空為空不為空結(jié)果:關(guān)于取出list內(nèi)容的標(biāo)簽用法1) BeanActionpublic class BeanAction extends Actionpublic ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception List list = new ArrayList();for(int i=0;i=10;i+)UserForm user = new UserForm();user.setUsername(username+i);user.setPwd(pwd+i);list.add(user);request.setAttribute(list, list);
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年抗結(jié)劑項(xiàng)目合作計(jì)劃書
- 2025年稀土-鐵超磁致伸縮單晶材料項(xiàng)目合作計(jì)劃書
- 家具潔凈護(hù)理流程
- 新人培訓(xùn)指南
- 新能源太陽(yáng)能熱發(fā)電EPC總承包項(xiàng)目合規(guī)性評(píng)估與保障協(xié)議
- 網(wǎng)店平臺(tái)費(fèi)用及增值服務(wù)合同
- 抖音火花用戶實(shí)名認(rèn)證與平臺(tái)內(nèi)容審核及糾紛處理協(xié)議
- 水利樞紐工程安全施工及生態(tài)保護(hù)合同
- 網(wǎng)絡(luò)直播電商侵權(quán)責(zé)任界定補(bǔ)充協(xié)議
- 直播平臺(tái)與動(dòng)漫IP授權(quán)合作協(xié)議
- 2025年陜西咸陽(yáng)亨通電力(集團(tuán))有限公司招聘筆試參考題庫(kù)附帶答案詳解
- 2025年江蘇省南通市如東縣實(shí)驗(yàn)中學(xué)中考一模英語(yǔ)試題(原卷版+解析版)
- 小學(xué)二年級(jí)有余數(shù)的除法口算題(共300題)
- 【水利水電】李想 案例專項(xiàng)班教案 04-案例專項(xiàng)班(四)
- 漢字文化解密學(xué)習(xí)通超星期末考試答案章節(jié)答案2024年
- 光影中國(guó)學(xué)習(xí)通超星期末考試答案章節(jié)答案2024年
- DLT 572-2021 電力變壓器運(yùn)行規(guī)程
- 《急診與災(zāi)難醫(yī)學(xué)》第三版-教學(xué)大綱(修改完整版)
- 10KV及以下架空配電線路工程施工及驗(yàn)收規(guī)范
- 超市標(biāo)準(zhǔn)商品分類表格模板
- 《汽車板材料物流配送服務(wù)技術(shù)規(guī)范》團(tuán)體標(biāo)準(zhǔn)
評(píng)論
0/150
提交評(píng)論