What is Struts?基於 MVC Architectural Pattern 所開發的 Web Application Framework Craig McClanahan 在 2000 年提出, 2001 年 6 月 release struts 1.0 。 Hosted in Apache Jakarta project 將開發 web 程式之 best practice 以 Application Framework 的方式封裝,供開發人員重用。 為何有資格稱為 best practice ?
4.
Must Read when Architecting J2EE Applications P of EAA Core J2EE Patterns 2/e
5.
Struts 與 J2EECore Patterns Struts 實作了下列 J2EE Core Patterns Application Controller (PEAA) Front Controller (PEAA) View Helper (PEAA:Template View) Service to Worker Dispatcher View
6.
Struts Framework 的定位Web tier / Persistence /workflow Your Code WebLogic / WebSphere ? jRocket VM / JDK ? Linux / Windows ? Struts is one of your architectural decisions
框架 (Framework) Aframework is a reusable, semi-complete application( 半成品 ) that can be specialized to produce custom applications. Application frameworks are for reifying( 具體化 ) proven software designs and implementations . Framework 通常針對特定領域來設計。 讓成功的設計經驗可以重複使用 !
使用 Framework 的經驗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.
MVC index.jsp LoginActionBO Request or Session Scope index.htm Java Bean Model View Controller Controller
49.
Struts 的 MVC模型 index.jsp Action Class Business Logic Request or Session Scope index.htm ActionForm Model View Controller ActionServlet
50.
Strengths of MVCPattern Provides a clear separation between: Business Logic (M) Output Presentation (V) Request Processing (C) Provides single point of workflow control Increases code manageability Increases code extensibility
使用 ActionForm 來協助處理HTML 表單 每一個 HTML Form 背後都有一個 ActionForm 來 support 。 id password <<ActionForm>> LoginActionForm id password getId()/setId() getPassword() setPassword() reset() validate()
JSTL 與 StrutsTag ,何者優先 ? 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 優先 !
69.
JSTL 與 Strutstag 取捨準則 ( 摘自 Struts in Action by Ted Husted) 使用 JSTL 取代 <bean:…> 與 <logic:…> 繼續使用 <html:……> 目前 Struts 正在開發 Struts-EL ,未來在 <html:…> 中將可使用 Expression Language .
70.
使用 Struts 控制項取代傳統 Html 控制項 目的 : 使用 Struts 的 html 控制項才能利用 ActionForm 的好處。 有時會和 JSTL 一起合併使用。