Presentation is loading. Please wait.

Presentation is loading. Please wait.

Component-Based Software Engineering Internet Applications Paul Krause.

Similar presentations


Presentation on theme: "Component-Based Software Engineering Internet Applications Paul Krause."— Presentation transcript:

1 Component-Based Software Engineering Internet Applications Paul Krause

2 Lecture 8 - Internet Applications Contents  Reminder of Client-Server architectures  Client-side programming with Applets and JavaScript  Server-side programming with JSP and Servlets

3 Client/server Architecture Server Client Internet Browser, Applets, … Client Internet Browser, Applets, … Database, servlets, …

4 Generic 5-tier Architecture Client Tier Presentation Business Rules Integration Resources

5 Application Components  Web pages HTML + scripting language code HTML + scripting language code Provides dynamic processing of data and modification of visual appearance Provides dynamic processing of data and modification of visual appearance  Program components Perform the main computations Perform the main computations Receive input from HTML forms Receive input from HTML forms Present output as web-pages Present output as web-pages  Configuration files Enables application to be quickly deployed on different servers Enables application to be quickly deployed on different servers

6 Types of Program Component  Controller components e.g. selection and customisation of the web-pages to return to the client e.g. selection and customisation of the web-pages to return to the client  Session beans encapsulate information and operations specific to a client session encapsulate information and operations specific to a client session stateless session beans - e.g. check data entrystateless session beans - e.g. check data entry stateful session beans - e.g. shopping cartstateful session beans - e.g. shopping cart  Entity beans provide access to persistent data provide access to persistent data

7 A statefull session bean public class BasketBean { private HashMap contents = new HashMap; public void addItem(Long itemid) { … } public void updateItem(Long itemid, int quantity) { … } public Set getItems( ) { … } public int getQuantity(Long itemid) { … } public void deleteItem(Long itemid) { … } public int numberOfItems( ) { … } }

8 Internet Programming in Java  Java-based technologies include:  Client-side: Applets Applets JavaScript JavaScript  Server-side: JSP - Java Server Pages JSP - Java Server Pages Java Servlets Java Servlets

9 Lecture 8 - Internet Applications Contents  Reminder of Client-Server architectures  Client-side programming with Applets and JavaScript  Server-side programming with JSP and Servlets

10 HelloFromVenus.java import java.awt.*; import java.applet.Applet; // Copyright (c) 1999-2002, Xiaoping Jia. public class HelloFromVenus extends Applet { public void paint(Graphics g) { public void paint(Graphics g) { Dimension d = getSize(); g.setColor(Color.black);g.fillRect(0,0,d.width,d.height); g.setFont(new Font("Helvetica", Font.BOLD, 24)); g.setColor(new Color(255, 215, 0)); // gold color g.drawString("Hello From Venus!", 40, 25); g.drawImage(getImage(getCodeBase(), "Venus.gif"), 20, 60, this); 20, 60, this); }}

11 Invoking the Applet <HTML><HEAD> Object-Oriented Software Development Using Java | HelloFromVenus Applet Object-Oriented Software Development Using Java | HelloFromVenus Applet </HEAD> <CENTER> Here is the Hello From Venus Applet Here is the Hello From Venus Applet </CENTER> Venus photo courtesy of NASA. </BODY></HTML>

12 JavaScript  Notation is close to Java, although with some important differences no explicit types for variables no explicit types for variables simplified structure to the code - a “scripting language” simplified structure to the code - a “scripting language”  But provides a powerful client-side processing and scripting language  Following examples from Lano et al, Software Design Using Java 2

13 <HTML><HEAD> Date Check Program Date Check Program // Some Java-like processing stuff goes in here // … </SCRIPT></HEAD><BODY> Click Refresh or Reload to run script again </BODY></HTML>

14 var firstNumber, secondNumber, number1, number2; firstNumber = window.prompt("Enter month (1--12)", "1"); secondNumber = window.prompt("Enter day (1--31)", "1"); number1 = parseInt(firstNumber); number2 = parseInt(secondNumber); if (1 <= number2 && number2 <= 31 && (number1 == 1 || number1 == 3 || number1 == 5 || number1 == 7 || number1 == 8 || number1 == 10 || number1 == 7 || number1 == 8 || number1 == 10 || number1 == 12)) number1 == 12)) { document.writeln(" Date is correct "); } else if (1 <= number2 && number2 <= 30 && (number1 == 4 || number1 == 6 || number1 == 9 || number1 == 11 )) (number1 == 4 || number1 == 6 || number1 == 9 || number1 == 11 )) { document.writeln(" Date is correct "); } else if (1 <= number2 && number2 <= 29 && number1 == 2 ) { document.writeln(" Date is correct "); } else { document.writeln(" Date is not correct! "); }

15 Browser Events Event HTML Syntax Page is loaded Button is pressed <INPUTTYPE = “button” VALUE = “command” ONCLICK = “function( )”> Mouse is moved Mouse over element Form entry active

16 Lecture 8 - Internet Applications Contents  Reminder of Client-Server architectures  Client-side programming with Applets and JavaScript  Server-side programming with JSP and Servlets

17 JavaServer Pages (JSP)  Works on the Server side to add functionality to HTML pages  Typically, JSP is used to add more complex functionality than JavaScript  JSP has a much closer relationship with Java Beans: Beans can be invoked from within JSP files Beans can be invoked from within JSP files Indeed, this is recommended to separate the GUI (html) from back-end code (Beans) Indeed, this is recommended to separate the GUI (html) from back-end code (Beans)

18 What does being a Bean mean?  In this context it is simply an instance of a Java class, conforming to an agreed pattern: The class has a no argument constructor The class has a no argument constructor Properties are accessed through “get” methods (“is” methods in the case of booleans) Properties are accessed through “get” methods (“is” methods in the case of booleans) Properties are updated through “set” methods Properties are updated through “set” methods  A JSP file then knows how to interface to it

19 A Booking Bean public class BookingBean { private int month; private int day; private String name; private String number; private boolean smoking: public BookingBean( ) { } // no argument constructor public void setMonth(String mon) {month = Integer.parseInt(mon); } public String getMonth( ) {return “ “ + month;} …

20 Using a Bean in JSP  Within a Java Server Page, we may wish to update and read a particular instance of the BookingBean class.  There is a simple mapping from lines in a JSP script, and the equivalent Java statements  This mapping is enabled by usage of the Java Bean coding guidelines

21 Creating and updating a Bean Corresponds to the Java statement: BookingBean booker = new BookingBean( ); Corresponds to the Java statement: booker.setMonth(request.getParameter(“month”)); Note, in this last case request is a Java object representing an HTTP request

22 Example jsp file <jsp : setProperty name = “booker” property = “month” param = “month”/> name = “booker” property = “month” param = “month”/> <jsp : setProperty name = “booker” property = “day” param = “day”/> name = “booker” property = “day” param = “day”/> // … <HTML> Echo Parameters Echo Parameters <BODY> Thank you, <jsp:getProperty name = “booker” property = “name” /> for your booking. You requested …

23 Java Servlets  Servlets use Java packages for server side processing of internet applications  This is a pure Java approach, rather than the hybrid Java/HTML approach of JSP  Can therefore write better structured, and easier to debug applications

24 Summary  A quick survey of Java technologies for Internet Applications  We saw the different needs of: client-side programming - relatively light-weight processes for data validation and gui configuration client-side programming - relatively light-weight processes for data validation and gui configuration server-side programming - more computationally intensive applications with access to persistent data sources server-side programming - more computationally intensive applications with access to persistent data sources  Structure these applications using ideas from Software Components to avoid a serious mess!


Download ppt "Component-Based Software Engineering Internet Applications Paul Krause."

Similar presentations


Ads by Google