Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark.

Similar presentations


Presentation on theme: "Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark."— Presentation transcript:

1

2 Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark

3 Agenda  JDeveloper 10g overview  Application Developer Framework (ADF)  Web Development with Struts

4 Full Lifecycle Support Deploy Test Build Design DebuggingTuning Data Modeling ApplicationModeling Coding Deployment ConfigurationManagement IDEPlatform Infrastructure

5 JDeveloper Framework Support  J2EE Frameworks – Application Development Framework (ADF) – Apache Struts support – ADF Business Components – Oracle 9i/AS10g Toplink – UiX – Java Server Faces (JSF)

6  Implements standard J2EE best practices  Model-View-Controller (MVC) design pattern  Focus on the application, not the “plumbing”  Consolidation and evolution of previous frameworks Oracle ADF End-to-end J2EE Framework Business Services Web and Wireless Clients Rich Clients Model Controller

7 ADF – Productivity With Choice View Controller Model Business Services Swing / JClientJSPADF UIXJSF Rich ClientWeb / Wireless Struts ADF Bindings ADF Data Control Java Classes EJB Session Beans Web Services ADF Business Components Service Object JDBC EJB Finders TopLink Queries ADF Business Components Query Object Data Access ADF Business Components Entity Object Java ClassesEJB Entity Beans TopLink Mapping Persistent Business Objects ADF Metadata Services

8 Struts Model 1 Architecture  Browser access JSP pages – JSPs access JavaBeans that represent model  Control de-centralized – current page display, determined next page to display  Complex navigation requires use of scriplet code – Blurs the line between presentation and navigation code and making reuse difficult  Not a model to use in practice - maintenance difficult and does not scale well

9 Struts Model 1 Architecture Decentralized controller - in each JSP page Model 1

10 Struts Model 1 Architecture Servlet/ JSP Web Server Servlet/ JSP No MVC - Statically Linked Pages

11 Struts Model-View-Controller ~ Model 2  Introduces a controller servlet – Controller Servlet handle the data access and navigational flow – JSPs handle presentation  Controller centralizes the logic for dispatching requests to the next view based on the request URL, input parameters, and application state  Controller also handles view selection, which decouples JSP pages and servlets from one another

12 State Change Change Notification State Query Struts Model-View-Controller ~ Model 2 Servlet JavaBean Enterprise JavaBean Controller JSP View HTTP Request HTTP Response View Selection Database Model JDBC DB User Actions

13 Struts Model-View-Controller ~ Model 2 Servlet/JSP Controller Web Server Applying MVC to a Page Flow

14 Struts What is It ?  Open source Apache Jakarta Project  An implementation of MVC paradigm  A framework written in Java, to build web tier employing servlets, JSPs and XML  De facto standard for J2EE MVC applications  Bundled with JDeveloper and works on OC4J

15 Struts Components  ActionServlet class – Part of controller that receives user input and state changes and issues view selections  Action class – Part of controller that interacts with model to execute a state change or query  ActionForm Beans – Data (from Form) bundled into Javabean for reuse and perform validation  ActionForward class – stores path to a page where the user is sent to  ActionMapping – holds mapping that tells controller which Actions, ActionForms, ActionsForwards to use

16 Struts Components (2)  Struts-config.xml – Glue of the framework - holds declarations of the earlier listed components and other details. ActionServlets reads this file and create the configuration objects in memory  Strut Tag Libraries – Custom tags that simplify working with Struts aiding the view component and access Model thru’ Java Beans  Property files – store messages and handle different languages

17 Struts Struts Pictorially Page 1 Controller Action2.java Struts- config. xml Mappings Business Logic Layer Data Layer View Layer Business Bean 1 JSP Engine Jsp 1 Action3.java Action4.java Action1.java Business Bean 2 Business Bean 3 Jsp 3 Form Bean 1 Form Bean 2 Other Bean 1 request/session Web Browser Database path action [form bean] [forwards] App Server Jsp 2 JDBC

18 Struts ActionForm  Holds state and behavior for user input  ActionForms are JavaBeans with reset() and validate() methods for user input  ActionForm extends org.apache.struts.action.ActionForm  Typically one ActionForm bean created for each HTML form  ActionForm has corresponding property for each field on HTML form

19 Struts ActionForm Example public final class FAQForm extends ActionForm { private String question; private String answer;.. public String getQuestion(){ return question; } public void setQuestion(String question) { this.question = question; }.. public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); if ((getQuestion() == null) || (getQuestion().length() < 1)) errors.add("question", new ActionError("errors.question.required"));.. return errors; }

20 Struts Action  Action class receives the ActionForm(which holds the data) and you perform action/processing here  Action provides a loose coupling between Web tier and business tier  Controller decides which Action class, using the mapping info  Action is invoked by calling perform() method

21 Struts Action - Example public final class FAQQueryAction extends Action { public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String result = null;... try { result = FAQHelper.getFAQHelper().query(actionForm, request); request.setAttribute("action", Constants.QUERY); }... return mapping.findForward( “ result ” ); }

22 Struts ActionMapping <action path="/faqQuery" type="faqapp.web.struts.actions.FAQQueryAction" name="FAQQueryForm" scope="request" validate="true" input="/faqQuery.do">  ActionMapping object maps the Actions to URI, or path  Specified in struts-config.xml

23 Struts ActionForward  Encapsulates the destination of where to send control upon completion of the Action  The destination(JSP, HTML file, servlet) is detailed in the configuration file – struts-config.xml  Objects that have logical name for referring and a path property <forward name="success" path="/WEB-INF/FAQQuery.jsp"/>

24 Struts ActionServlet  Primary task is to route request URI to an Action class using the configuration information(struts-config.xml)  Is the director - working behind the scene, administering the behavior of controller  Configured using web.xml of the application and mapped to receive url patterns such as *.do  Only one ActionServlet can be loaded for an application  Used as a black box in most cases, though it can be extended

25 Struts struts-config.xml  Holds declarations of Struts components that define the configuration  Living blueprint of your application – What fields are on the forms – Where JSPs are found – Knows about every action and the resources needed  Power and flexibility of Struts is due to extracting out configuration information, across the frame work into struts-config.xml

26 Struts struts-config.xml - Example <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN ” "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd"> <form-bean name="FAQQueryForm “ type="faqapp.web.struts.forms.FAQQueryForm" /> <action path="/faqQuery" type="faqapp.web.struts.actions.FAQQueryAction" name="FAQQueryForm" scope="request" validate="true" input="/faqQuery.do">

27 Struts A Look into web.xml action org.apache.struts.action.ActionServlet application ApplicationResources config /WEB-INF/struts-config.xml debug 2 detail 2

28 gets data to display (adds to beans in request/session)…or saves data from beans via business rules creates/reuses any associated form bean creates looks up path to determine action/ form bean interacts with lower layers - acts as adaptor between HTTP and layers below if submit, auto populates form bean from request params Page 1 Controller Action2.java Struts- config. xml Mappings Business Logic Layer Data Layer View Layer Business Bean 1 Jsp Engine Jsp 1 Action3.java Action1.java Business Bean 2 Business Bean 3 Jsp 2Jsp 3 Form Bean 1 Form Bean 2 request/session Web Browser Business Data reads on start-up incoming requests path action [form bean] [forwards] passes control to relevant action to handle returns appropriate forward relevant page called processes custom tags – fill form elements from beans, display internationalized messages pure HTML sent to browser Jsp 2 Action2.java Form Bean 2 Application Server Jsp 2 How it all Works

29 Struts JSP Tag Libraries  HTML JSP custom tags – bridge between a JSP view and the other components of a Web application – Tags relating to HTML forms, message and error handling, maintaining hyperlinks and internalization  Bean JSP custom tags – Tags useful for accessing beans, their properties,and defining beans based on access – Create new beans based on the value of request cookies, headers, and parameters in any scope  Logic tags – Tags for conditional generation of output text, looping, comparison/sub-string matching

30 Struts Using Struts JSP tags Welcome! Welcome ! Welcome World! Sign in Sign out

31 Demonstration Develop a Web Application based on Struts and EJBs as the model


Download ppt "Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark."

Similar presentations


Ads by Google