OOSSE - OO Review Review session A review of other OO technologies and may be useful for exam (not required for assignment) OO web development philosophy JSP and OO MVC models review Struts Tag libaries Ajax Summary Source: j.c.westlake@staffs.ac.uk Slide 1 OOSSE - OO Review OO Software Engineering By now you have experienced UML JSP Let us review the OO tenets (beliefs, principles) and how JSP reflects these tenets What are the tenets of OO? Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 2 OOSSE - OO Review UML for web development Can we also reflect on this? How does UML help in web development What diagrams have been useful? What else is available from UML? Answer: Web Application Extensions (WAE) A set of UML modelling aspects designed to help the web developer model web applications Reading here Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 3 OOSSE - OO Review JSP engine reviewed The JSP engine builds a servlet. The HTML portions of the JavaServer Page become Strings transmitted to print methods of a PrintWriter object. The JSP tag portions result in calls to methods of the appropriate class whose output is translated into more calls to a println method to place the result in the HTML document. Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 4 OOSSE - OO Review JSP engine reviewed JSP actually supports real Java code, not a new scripting language. Java code inside JSP is added to methods of a Java Servlet that are generated the first time the JSP is requested. Uses set of pre-established objects by the Web server that they use to generate a dynamic Web page. Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 5 OOSSE - OO Review OO web development philosophy Web development... A collection of individual objects, that act on each other Different from traditional view in which a program may be seen as a collection of actions, or simply as a list of instructions Objects capable of receiving messages, processing data, and sending messages to other objects New object that inherits features from existing objects What we are seeing is a move from scripting/HTML websites to a more OO philosophy Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 6 OOSSE - OO Review JSP Model 1 architecture JSPs to handle HTTP requests Data layer via Java Beans For small web applications this model is okay but more complex commercial applications a different model is required – Model 2 Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 7 OOSSE - OO Review Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 8 OOSSE - OO Review JSP Model 2 architecture Also called Web Model-View-Controller (MVC) design see next slide Separates the GUI from the business layer Uses a Java Servlet to receive the HTTP requests from the browser and communicate with the model layer JSPs only used for presentation – the Servlet determines which view to send back to the client Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 9 OOSSE - OO Review Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 10 OOSSE - OO Review Servlets - “nuts and bolts” The Servlet class extends the HttpServlet class Essentially this means it can use the attributes/methods of this class The HttpServlet class has a number of methods an init( ) method - used for connecting to databases dsn’s it has service method e.g. doGet, doPost, doPut and doDelete the above methods are the “meat” of the HttpServlet class It uses two objects, namely HttpServlet Request and HttpServlet Response Here is an example of the MVC approach <link> Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 11 OOSSE - OO Review Other technology - Apache Struts Interesting web architecture framework http://struts.apache.org/ Designed to handle requests made by the client or by web browsers Apache struts is an open source framework using servlet and JSP See next slide for picture of struts Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 12 OOSSE - OO Review Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 13 OOSSE - OO Review Other technology - Tag Libaries Custom tags are dynamic page elements. This means they can provide functionality to a webpage using a syntax similar to normal HTML tags. The functionality is up to you… They can provide an alternative (or an additional) mechanism to JavaBeans for dynamic scripting As an example see this link <JSP Controls> Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 14 OOSSE - OO Review What do you need? There are two components to a tag: A Java tag handler class that implements the tag’s functionality. A Tag Library Descriptor (TLD) in the form of an XML file describing the tag. By including this tag on a JSP page you have access to its functionality. Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 15 OOSSE - OO Review Java handler class Yes, you have to code the functionality in Java. So why bother? Why not just create a JavaBean instead? For standard webpage scripters, tags are more familiar and provide a simpler mechanism. For web application developers, JavaBeans integrate more fully with the full application environment so are more powerful. Your choice…. Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 16 OOSSE - OO Review Tag Library Descriptor A TLD is a (fairly) simple XML file that describes a set of custom tags. You can put as many or as few custom tags in a TLD and more than one TLD can be used in a single project. In principle, you could create many useful tags and zip them into one .jar file for easy resusability. Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 20 OOSSE - OO Review Other technology - Ajax AJAX, shorthand for Asynchronous JavaScript and XML exchanging small amounts of data with the server behind the scenes Speeds up web interaction Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 30 OOSSE - OO Review Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 31 OOSSE - OO Review Summary Doing development in an OO style is beneficial even if the software being used is not directly OO For the enterprise level OO is evident in the selection of technologies mentioned Version 1.1 Dec 2008 Source: j.c.westlake@staffs.ac.uk Slide 32