240 likes | 370 Views
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. Our Contact Point.
E N D
j.c.westlake@staffs.ac.uk, edited by NAS 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
j.c.westlake@staffs.ac.uk, edited by NAS 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.
j.c.westlake@staffs.ac.uk, edited by NAS 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)
j.c.westlake@staffs.ac.uk, edited by NAS 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
j.c.westlake@staffs.ac.uk, edited by NAS 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.
j.c.westlake@staffs.ac.uk, edited by NAS 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)
j.c.westlake@staffs.ac.uk, edited by NAS 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.
j.c.westlake@staffs.ac.uk, edited by NAS 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!
j.c.westlake@staffs.ac.uk, edited by NAS 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
j.c.westlake@staffs.ac.uk, edited by NAS Benefits of Web-Enabledn-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.
j.c.westlake@staffs.ac.uk, edited by NAS 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.
j.c.westlake@staffs.ac.uk, edited by NAS 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
j.c.westlake@staffs.ac.uk, edited by NAS 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.
j.c.westlake@staffs.ac.uk, edited by NAS 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
j.c.westlake@staffs.ac.uk, edited by NAS 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.
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"; ResultSetrs = 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>
j.c.westlake@staffs.ac.uk, edited by NAS 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
j.c.westlake@staffs.ac.uk, edited by NAS 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
j.c.westlake@staffs.ac.uk, edited by NAS Example • http://fcet11.staffs.ac.uk:8080/nas1/examples/SimpleGuestList.jsp
JSP Translation process Browser Tier Server Tier Database Tier Query for data content HTTP Server TOMCAT Browser 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
j.c.westlake@staffs.ac.uk, edited by NAS Result Returned
j.c.westlake@staffs.ac.uk, edited by NAS 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
j.c.westlake@staffs.ac.uk, edited by NAS 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