Building Web Applications With The Struts FrameworkSession.ppt
《Building Web Applications With The Struts FrameworkSession.ppt》由会员分享,可在线阅读,更多相关《Building Web Applications With The Struts FrameworkSession.ppt(57页珍藏版)》请在麦多课文档分享上搜索。
1、,Building Web Applications With The Struts FrameworkSession WE06 11/20/2002 10:00-11:00Craig R. McClanahan Senior Staff Engineer Sun Microsystems, Inc.,Session Outline,Web Applications Backgrounder The Model-View-Controller Architecture The Struts Framework Building A Web Application With Struts Res
2、ources,Web Applications Backgrounder,Web Applications Backgrounder,Web applications run over the HTTP protocol: Request/response oriented Stateless Web applications use varied presentation (markup) languages, and talk to varied client hardware devices: “Standard HTML” - not! Varying dynamic and Java
3、Script capabilities Wireless devices vary in capabilities, language dialect, and input device support,Simple Solutions . for Simple Problems,For relatively simple applications, a simple architecture works fine For each page in the user interface . Create a servlet, JSP page, or something similar The
4、 page includes: Logic to create the user interface Logic to retrieve required information from the database Logic to perform the appropriate business transaction Logic to update the corresponding database information And its all mixed together in one source file This works fine for a Guest Book app,
5、 but what about something bigger?,What About Large Scale Applications?,Disparate skill sets required: Presentation Layer- User interface design, visual appearance, interaction model Application Layer Functional business logic to perform required transactions Persistence Layer Databases, directory se
6、rvers, messaging, Enterprise JavaBeansTM (EJBs) Application Deployment Networks, firewalls, public key infrastructures, load balancing, failover We need a fundamental organizing principle: The Model-View-Controller (MVC) architecture,The Model-View-Controller (MVC) Architecture,The Model-View-Contro
7、ller Architecture,Divides the overall functionality of an application into three layers: Model Layer Contains the functional business logic of the application, as well as a representation of the persistently stored data backing the application View Layer Contains the user interface, including mechan
8、isms to accept user input and render results Controller Layer Contains the logic that manages the flow of individual requests, dispatching to the appropriate business logic component,The Model Layer,Functional business logic: Should be modelled as JavaBeans or Session EJBs Should be reusable in non-
9、web environments API exposes public methods for each logical unit of work (while hiding the details) Persistent data storage: Should manage permanent storage of application data Typically shared across many applications API should expose data retrieval and storage operations (while hiding the mechan
10、isms),The View Layer,Creation of the user interface: Typically in HTML or an XML-based dialect Normally a combination of static and dynamic content Actual content varies depending on: Device or browser type User preferences / personalization Internationalization and localization requirements Accessi
11、bility requirements,The Controller Layer,Incoming requests flow through a common path: Received by common component Standardized request pre-processing Dispatch to request-specific model component (business logic) Forward to business-logic-specified view component Standardized request post-processin
12、g Often called “Model 2 Design” in the JSP/Servlet community In modern design pattern terminology, Struts implements the front controller pattern.,The Struts Framework An Implementation of the MVC Architecture,The Struts Framework Architecture,The Struts Framework Model Layer,Struts does not restric
13、t implementation techniques for model layer JDBC-accessed databases Enterprise JavaBeans O-R mapping tools Optional JDBC connection pool available Common design pattern: Action acquires information from persistence tier Exposes information as request/session attributes View layer pulls data from att
14、ributes for display,The Struts Framework View Layer,Form Bean maintains state of form input fields across requests: ActionForm Standard JavaBean design pattern DynaActionForm Property names and types defined in Struts configuration file In addition to properties, form beans define two standard metho
15、ds: reset() - Reset form properties to initial state validate() - Perform field-level validations Form bean properties are typically Strings Allows redisplay of invalid input,The Struts Framework View Layer,Internationalization Support enables locale-specific applications Locale Standard Java class
16、representing a choice of language and/or country MessageFormat Standard Java class representing an individual message with replaceable parameters: “0 is not a valid credit rating” MessageResources Struts abstraction around sets of messages for supported locales ActionErrors / ActionMessages Struts c
17、ollections of localized messages,The Struts Framework View Layer,JSP Custom Tag Libraries If you are using JSP pages for your presentation struts-bean.tld Fundamental bean manipulation and internationalization struts-html.tld “Smart” HTML elements struts-logic.tld Basic conditionals and iteration st
18、ruts-template.tld Basic layout management,The Struts Framework View Layer,Standard tag libraries added in Struts 1.1: struts-nested.tld - “Nested” variants of standard tags that resolve relative references against beans struts-tiles.tld Full features layout management library Contributed libraries a
19、dded in Struts 1.1: struts-xxx-el.tld Versions of standard Struts tag libraries that support the expression language syntax of JSP Standard Tag Library,The Struts Framework View Layer,Validation Framework No-code-required field level validations Configured in an XML document included in the web appl
20、ication Optionally generates client side JavaScript to enforce validation rules Extensible architecture,The Struts Framework Controller Layer,ActionServlet Standard implementation of controller At application startup, reads configuration file and initializes resources Struts 1.1 PlugIn General start
21、/stop hook On each request, implements the standard Struts request processing lifecycle (in Struts 1.1, implemented in RequestProcessor) Specialization / customization via subclassing Struts 1.1 Sub-application modules support,The Struts Framework Controller Layer,Action Standard base class for busi
22、ness logic components and adapters: Mapped to logical names by request processor Single instance per application (must be thread safe) Instantiated as needed, like servlets Implements the “Command Pattern” execute() - Invoked for each request Can (but typically does not) create response content dire
23、ctly Typically returns ActionForward to select resource to prepare response,The Struts Framework Controller Layer,Standard Request Processing Lifecycle 1: processLocale() - Record users locale preference (if not already present) processPreprocess() - general purpose pre-processing hook processMappin
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- BUILDINGWEBAPPLICATIONSWITHTHESTRUTSFRAMEWORKSESSIONPPT

链接地址:http://www.mydoc123.com/p-379159.html