1 / 85

Observations on JCOE Project

Observations on JCOE Project. Chun-Feng Liao Nov 13,2003 NCCU Computer Center. JCOE 對中心來說有什麼意義 1. 帶來許多正規而嚴謹的開發方法論 (RUP) 、工具 (Eclipse , Ant) 與應用程式框架 (Struts 、 OJB) JCOE provides us a chance to evalute these skills .

cutler
Télécharger la présentation

Observations on JCOE Project

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Observations on JCOE Project Chun-Feng Liao Nov 13,2003 NCCU Computer Center

  2. JCOE對中心來說有什麼意義 1 • 帶來許多正規而嚴謹的開發方法論(RUP)、工具(Eclipse , Ant)與應用程式框架(Struts、OJB) • JCOE provides us a chance to evalute these skills . • Average loading of 6F will become higher in the future .Somehow we have to find a good way to imporve efficiency. • We need not to apply all these skills , but JCOE did point out a good direction for us.

  3. JCOE對中心來說有什麼意義 2 • 參與JCOE專案所習得的知識,可能會對幾位應用系統組幾位技術師未來做架構與組織決策時提供寶貴的經驗。 • 在參與過程中也許有很多衝突、挫折與不愉快,但我個人感覺它們應該都是一個組織成長的過程,最後總會找到一個最好的方向。

  4. Frameworks and JCOE Project Chun-Feng Liao Nov 13,2003 NCCU Computer Center

  5. Frameworks in JCOE • Front-end : Apache Struts • Business Logic : Frameworks extracted from Domain model / Use cases . • Persistence : Apache OJB

  6. Why Framework ? • Encapsulate an expert’s experiences or knowledges . • Encourages the reuse of software components . • Makes development easier and software more scalable .

  7. Applying SAWA Frameworks • Framework Develop time • 2002.11 ~ 2003.06 (7個月/ 1人 ) • Applications Develop time • 改寫時間2003.7 ~ 2003.8 (2個月/ 2人 )

  8. Experiences of Applying Frameworks • Developers should have strong OO backgrounds. • 在Programmer沒有足夠OO Background的情況下套用Framework可能造成反效果. • Learning curve should be taken into account. • Once framework is on-line , it will be very hard to modified.

  9. Struts Framework in Practice Chun-Feng Liao Nov 13,2003 NCCU Computer Center

  10. Introduction • Struts Framework will be the first Framework to adopt in JCOE. • Struts is a Open-source project hosted in Apache. • Struts involves significant learning curve , especially its config files.

  11. Struts文件 • 官方版User Guide • 包含所有詳細設定、自訂標籤的細節。 • http://jakarta.apache.org/struts/userGuide/index.html • 文件結構簡介

  12. Struts Backgrounds

  13. 使用者認証:早期的做法 before 2001.04 servlet 資料庫 jsp 資料庫 jsp JavaBean (2001.04 ~ 2002.03(some) ~ 2003.06(most)) 資料庫

  14. 用Servlet將business logic封裝 html Servlet 資料庫 set data jsp Java Bean read data Request or Session Scope

  15. 範例:使用者認証 index.htm LoginProcessor 資料庫 set data mainMenu.jsp UserDataBean read data Request or Session Scope

  16. 將Servlet功能細分 index.htm Controller LoginAction 資料庫 mainMenu.jsp Java Bean Request or Session Scope

  17. MVC index.htm Controller View LoginAction 資料庫 mainMenu.jsp Java Bean Model Request or Session Scope (Used by Java Team of 6F from 2003.06 )

  18. Struts Framework

  19. Struts概觀

  20. Struts主要元件 • Struts JSP自訂標籤庫 • ActionForms • Action classes • ActionServlet • struts-config.xml

  21. 使用Struts控制項取代傳統Html控制項 • 目的:使用Struts的html控制項才能利用ActionForm的好處。 • 有時會和JSTL一起合併使用。

  22. 傳統的Html Form <html> <body> <form action=“sayHello.do”> <input type=“text” name=“userName”/> <input type=“submit” /> </form> </body> </html>

  23. 使用Struts控制項取代html控制項 • 修改web.xml • 副檔名改成.jsp • 修改tag

  24. 使用Struts控制項取代傳統html控制項 • 修改web.xml <taglib> <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri> <taglib-location> /WEB-INF/tld/struts-html.tld </taglib-location> </taglib> TLD真正的位置 隨便取個名字,識別用.

  25. 使用Struts控制項取代傳統html控制項 <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <html:html> <html:form action=“sayHello.do”> <html:text property=“userName” /> <html:submit /> </html:form> </html:html> 相同! 要先宣告 前面加上html的prefix

  26. ActionForm • 在ASP.NET中每一個aspx後面有所謂WebForm,處理顯示邏輯。 • 在Struts中,每一個Form後面也會有一個ActionForm。

  27. HTML的Form如何與ActionForm對映? • 基本上每一個<html:form>……</html:form>背後都會有一個ActionForm。 • 表單的每一個輸入欄位原則上對映到JavaBean的一個property。

  28. 所對映到的屬性 範例 <html:html> <html:form action=“sayHello.do”> <html:text name=“userNameForm”property=“userName” /> <html:text name=“userNameForm”property=“password”/> <html:submit /> </html:form> </html:html> ActionForm名稱

  29. UserNameForm Package demo; Public class UserNameForm extends ActionForm { // 屬性和html form的要一一對應,名字也要相同 private String userName; private String password; // 每一個屬性都要有getter及setter public void setUserName(String userName) {…} public String getUserName() {…..} public void setPassword(){…..} public String getPassword() {….} } 如果有十個屬性怎麼辦? 使用DynaBean!

  30. 登記Form Bean <form-bean name=“userNameForm” type=“demo.UserNameForm” /> 通常出現在struts-config.xml的第二段

  31. 使用DynaBean <form-bean name=“userNameForm” type=“org.apache.struts.action.DynaActionForm” > <form-property name=“userName” type=“java.lang.String”/> <form-property name=“password” type=“java.lang.String”/> </form-bean> 使用單一Map物件儲存所有JavaBean的屬性

  32. 讀取ActionForm • JSTL • <c:out value=“${sessionScope.userNameForm.name}” /> • Struts-bean • <bean:write name=“userNameForm” property=“name” />

  33. JSTL與Struts Tag,何者優先? Should you use JSTL tags instead of Struts tags whenever you can? Sure, if your container supports Servlets 2.3 and JSP 1.2, and that’s what you want to do.(儘可能使用JSTL取代Struts標籤) If JSTL already existed, most of the Struts tags would neverhave been written. -Ted Husted ,Jakarta Struts technical lead. JSTL優先!

  34. JSTL與Struts tag取捨準則 • (摘自Struts in Action by Ted Husted) • 使用JSTL取代<bean:…>與<logic:…> • 繼續使用<html:……> • 目前Struts正在開發Struts-EL,未來在<html:…>中將可使用Expression Language.

  35. Action Class

  36. Action做些什麼? • 從ActionForm中取得資料 • 從request/response中取得資料 • 處理商業邏輯(含資料庫存取) • 將控制權forward到合適的View中

  37. SayHelloAction public class SayHelloAction extends Action { public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { UserNameForm myForm = (UserNameForm) form; …..(do something)… return (mapping.findForward("success")); } }

  38. 使用struts-config.xml控制ActionServlet行為! ActionServlet

  39. Struts-config.xml • Struts的核心,用來描述各元件的關係。 • 市面上有很多GUI工具可支援自動產生。

  40. struuts-config.xml主要區段 • 依先後次序為: • DataSource設定  (JDBC) • ActionForm設定  重要! • Global相關設定 • ActionMapping設定  重要! • Controller設定 • 其它設定(i18n,plug-in,…) • 我們只講ActionForm及ActionMapping,其它config的細節請自行參考struts線上文件。

  41. ActionForm區段 • 目的:在此宣告你寫的ActionForm及其代名(你要怎麼稱呼他?),以便在ActionMapping中做相對設定。 • 以<form-beans>…</form-beans>為界。 • <form-beans>中包含數個<form-bean>。

  42. ActionForm區段 <form-beans> <form-bean name="userNameForm" type="simple.form.SimpleForm“ /> <form-bean name=“anotherForm" type="simple.form.AnotherForm“ /> </form-beans> ActionMapping區段將使用這個名字來指稱你的FormBeans

  43. ActionMappings區段 • 目的:將jsp背後的ActionForm、發出的url 、Action class及其處理完後要forward的對象,四者間的關係連結起來。

  44. ActionMappings區段 • 如何將以下這幾個component的關係化成文字? /sayHello.do index.jsp ActionServlet Request Scope UserNameForm hello.jsp SayHelloAction success

  45. ActionMappings區段 <action-mappings> <action path="/sayHello" type="simple.action.SayHelloAction" name="userNameForm" scope="request" input=“index.jsp” > <forward name="success" path="/hello.jsp"/> </action> <action>…..</action> <action>…..</action> </action-mappings>

  46. DEMO • 觀察struts-config.xml • demo

  47. web.xml要做的設定 • 登記ActionServlet • 副檔名 • Tag library註冊 DEMO (觀察web.xml)

  48. 實作一個簡單的Struts應用程式

  49. Tools Inconsistency • Rose vs Together • Eclipse + Ant vs JBuilder • CVS vs Star Team Note : Even newest version of JBuilder only support Struts 1.0 (We use 1.1 in JCOE)

  50. 如何建置Struts應用程式 • 使用Eclipse

More Related