Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Enterprise/Server-side Java Introduction • Welcome! • As usual the module lasts for 12 weeks with the last week being a revision week. • For assessment details let us refer to the module web page. • Module leader is Nic Shulver [email protected], edited by NAS Slide 1 Enterprise/Server-side Java Our Contact Point • The course schedule details the subject we will be teaching each week as well as the practicals. • Books! - so many to choose from - some quite awful some good. • A list of books can be found on the Module Information page. • You do not have to buy a book - plenty in the library. [email protected], edited by NAS Slide 2 Enterprise/Server-side Java Other advice • Please see or email tutors about any aspect of the module during the 12 weeks. • If you have a problem understanding some of the material, then please ask tutors! • The slides that follow put “server-side Java for enterprise” in context • Note emphasis on key words (orange highlight) [email protected], edited by NAS Slide 3 Enterprise/Server-side Java Java Server Pages • • • • • • Format of lecture: Introduction What are Java Server Pages? (JSPs) What do you need to run JSPs? Demo of an example of a JSP in action Tutorial work will get you going straight away on understanding the architecture and running your first JSP [email protected], edited by NAS Slide 4 Enterprise/Server-side Java Overview/history - 90’s • Early web users were limited to static HTML. • Useful for presenting company information often in a hierarchical manner. • Little or no interaction with the user. • Java applets addressed this problem enabling additional code to be downloaded but still a problem of building customised information. • Dynamically generated HTML using the Common Gateway Interface (CGI) was also a proposed solution. [email protected], edited by NAS Slide 5 Enterprise/Server-side Java Year 2000 onwards • CGI and generated HTML was the forerunner for server-side Java based techniques. • Java Servlets. • JavaServer Pages (JSP). • Component-based computing (Enterprise JavaBeans). • Active Server Pages (ASP, ASP.net). • Personal Hypertext Preprocessor (PHP) [email protected], edited by NAS Slide 6 Enterprise/Server-side Java Evolution of Applications • One-tier - mainframe based/dumb terminal/central application source. • Also modern standalone/PC/Mini computers/multi copy of application. • What we might think of as a simple, “normal” application. [email protected], edited by NAS Slide 7 Enterprise/Server-side Java Evolution of Applications • Two tier - client-server - distributed part of the application on the client (GUI) and part on the server. • Early versions of client-server required installation of GUI and business logic. • Recently, Java applets downloadable on demand. • With server-side servlets and JSP, no download and the browser is used as the interface - this is a good solution! [email protected], edited by NAS Slide 8 Enterprise/Server-side Java Evolution of Applications • Three tier/n-tier - user interface(UI) layer; the business layer(BL) and the database layer(DL) • UI - presentation of information, browsers such as Firefox or Internet Explorer on the client • BL - logic of procedures about the business, best done on a server [why?] • DL - where the data is stored - usually a relational database but could be an object oriented database [email protected], edited by NAS Slide 9 Enterprise/Server-side Java Benefits of Web-Enabled n-tier Applications • Web applications enable ‘things’ to be done from a web browser - e.g. online banking. • Run from anywhere – no installation fee, may incur network communication costs of course. • Cost reduction: • Browser based interface is easy to use - little training required. • Development costs lower as using a standard interface. • No permanent installation on the user’s machine. • Use of open standards: • Maintenance easier. • Enhancement of applications easier. [email protected], edited by NAS Slide 10 Enterprise/Server-side Java Web Enabling Techniques • • • • How to develop web-based applications? How can a server process multiple requests? Need a fast response! Scalability - HTTP protocol - works in a stateless request-response mode - means it does not bind a server to a client for an inordinate amount of time. • Some techniques which can be used to concurrently satisfy thousands of requests. [email protected], edited by NAS Slide 11 Enterprise/Server-side Java Stuff that we need • We are going to spend the next four weeks looking at Java Server Pages (JSPs). • Just like when using ASP or PHP, we need a server that understands our JSP code. • We need an HTTP server which supports JSP. • We will use server software called “Tomcat” • Tomcat is running on one of our servers: fcet11 • You can also download Tomcat for home use and run a server on your home PC [email protected], edited by NAS Slide 12 Enterprise/Server-side Java What are JSPs? • They are HTML documents that are interleaved with Java which provides the dynamic content. • JSPs are server-side - they accept a request and generate a response (an HTML document). • JSP is the next generation on from Servlets - an extension of Servlets with more power and flexibility. • JSP is the equivalent of Microsoft’s Active Server Pages (ASP) technology and Zend's PHP environment. [email protected], edited by NAS Slide 13 Enterprise/Server-side Java JSPs… Servlets… ??? • JSPs are an extension of Java Servlet technology. • JSPs automatically generate Servlets which are Java class files run on the server. • • It is possible to code your own Servlets and include them in with your JSP web application. A useful source of information for JSPs and Servlet technologies is the Java Server Pages homepage at Sun: http://java.sun.com/products/jsp/index.html [email protected], edited by NAS Slide 14 Enterprise/Server-side Java Facts about JSPs • All JSPs have a file extension of .jsp • JSP is meant to be easier than Servlets. • Syntax of a typical JSP is on the next two slides. • Over the next four weeks we will look at the syntax of JSPs in depth. [email protected], edited by NAS Slide 15 simpleguestlist.jsp <html> <head> <title>An Example of a Simple JSP Accessing a database Model</title> </head> <body> <div align="center"> A Listing Of Guests </div> <br><br> <%@ page import="java.sql.*" %> <table width="100%" border="2" bgcolor="silver"> <tr><th width="50%">Email</th> <th width="25%">Firstname</th> <th width="25%">Lastname</th> </tr> <% try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:odbc:GuestBook"); Statement statement = conn.createStatement(); String sql = "SELECT * FROM GuestBook"; ResultSet rs = statement.executeQuery(sql); while (rs.next()) { %> <tr> <td><%= rs.getString("Email") %></td> <td><%= rs.getString("FirstName") %></td> <td><%= rs.getString("LastName") %></td> </tr> <% } %> </table> <% if (statement != null) statement.close(); if (conn != null) conn.close(); } catch (Exception e) {out.print(e);} %> </body> </html> Enterprise/Server-side Java Kit required • • • • What do you need to develop and run JSPs? JDK (Java Development Kit and runtime) Tomcat HTTP server With database interaction we need a database – we will use Access for convenience but MySQL is also of interest [email protected], edited by NAS Slide 18 Enterprise/Server-side Java Demo of a JSP • This example is a JSP which uses a DSN-less connection to the GuestBook database • The application model is essentially a JSP connecting to a database • It renders dynamically to the user’s browser the contents of a table • As the table changes the content of the page will reflect this change – hence it dynamic – built at each request [email protected], edited by NAS Slide 19 Enterprise/Server-side Java Example http://fcet11.staffs.ac.uk:8080/nas1/examples/SimpleGuestList.jsp [email protected], edited by NAS Slide 20 Enterprise/Server-side Java JSP Translation process Browser Tier Browser Server Tier HTTP Server TOMCAT Database Tier Query for data content Request: JSP translated into a Servlet .java file and then compiled into a Servlet class .jsp file (HTML interleaved with Java) Backend database usually on a separate database server Request:Browser page link to call .jsp(either via locator or a link on an HTML input page Response: HTML for output sent from Server Response HTML document Enterprise/Server-side Java Result Returned [email protected], edited by NAS Slide 22 Enterprise/Server-side Java Summary • We have established that JSP represents a technology that can be used for dynamic web applications • The market for this type of technology is well established (J2EE market) • JSP demands some programming skills but is more and more seen as an integration technology with can dovetail with technologies such as XML [email protected], edited by NAS Slide 23 Enterprise/Server-side Java Summary • We used an HTTP server which supports JSP • If you were choosing an ISP and wished to run JSP then you would need to check that they support JSP • We highlighted the features of a JSP • A .jsp file is essentially HTML with Java code inserts • When the .jsp file is called via a browser a .java file is created to represent Servlet source code and then the .java file is compiled into a bytecode file with a .class extension. • The compilation is only done once - subsequent calls to the JSP use the already compiled .class file [email protected], edited by NAS Slide 24