+ All Categories
Home > Documents > OOSSE Week 7 Java Server Pages Format of lecture: Introduction What are Java Server Pages? (JSPs)...

OOSSE Week 7 Java Server Pages Format of lecture: Introduction What are Java Server Pages? (JSPs)...

Date post: 19-Jan-2016
Category:
Upload: primrose-nicholson
View: 215 times
Download: 0 times
Share this document with a friend
21
OOSSE Week 7 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 Version 1.2 Nov 2009 Slide 1 [email protected]/ [email protected]
Transcript
Page 1: OOSSE Week 7 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.

OOSSE Week 7Java Server PagesFormat of lecture:IntroductionWhat are Java Server Pages? (JSPs)What do you need to run JSPs?Demo of an example of a JSP in action

Version 1.2 Nov 2009Slide [email protected]/[email protected]

Page 2: OOSSE Week 7 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.

OOSSE Week 7Web-Enabled ApplicationsObjectives of this session:-Overview/History.List the advantages of web-enabled

applications.Understand how object oriented technology

can help with this type of application.List technologies that make web-enabled

applications possible.List the capabilities of tools in developing this

type of application.Version 1.1 Nov 2008

Slide [email protected]/[email protected]

Page 3: OOSSE Week 7 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.

OOSSE Week 7OverviewEarly 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.

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 4: OOSSE Week 7 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.

OOSSE Week 7OverviewCGI-created HTML was the forerunner for server-side

Java based techniques.Java Servlets.JavaServer Pages(JSP).Component-based computing (Enterprise

JavaBeans).Active Server Pages (ASP).Hypertext Preprocessor (PHP)Visual Basic Web Classes.

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 5: OOSSE Week 7 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.

OOSSE Week 7

Evolution of Applications – good exam question!

One-tier - mainframe based/dumb terminal/central application source.

Standalone/PC/Mini computers/multi copy of application.

Two tier - client-server - distributed part of the application on the client(GUI) and part on the server.

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 6: OOSSE Week 7 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.

OOSSE Week 7

Evolution of Applications – good exam question!

Two tier - client-serverEarly versions of client-server required installation

of GUI and business logic.Recently, Java applets downloaded on demand.

With server side servlets and JSP no download and the browser is used as the interface - this is a good solution!

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 7: OOSSE Week 7 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.

OOSSE Week 7Evolution of ApplicationsThree tier/n-tier - user interface(UI) layer; the

business layer(BL) and the database layer(DL)

UI - presentation of information browsers such as Netscape or Explorer on the client

BL - logic of procedures about the businessDL - where the data is stored - usually a

relational database but could be an object oriented database

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 8: OOSSE Week 7 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.

OOSSE Week 7

Benefits of Web-Enabled n-tier ApplicationsWeb applications can be called self-service applications - they

enable ‘things’ to be done from a web browser - e.g. online banking.

Run from anywhere - installation free.Cost reduction:

Browser based interface is easy to use - little training required.

Development costs lower as using a standard interface.No installation.

Use of open standards:Maintenance easier.Enhancement of applications easier.

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 9: OOSSE Week 7 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.

OOSSE Week 7Web Enabling TechniquesHow to develop web-based applications and

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

There are a number of techniques which can be used to concurrently deal with thousands of clients

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 10: OOSSE Week 7 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.

OOSSE Week 7Stuff that we needJust like when using ASP or PHP, we need a

server that “understands” our JSP codeWe need an http server which supports JSPWe will use a (free) commercial server called

TomcatWe could use Glassfish, in part based on

Tomcat (http://en.wikipedia.org/wiki/GlassFish)

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 11: OOSSE Week 7 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.

OOSSE Week 7What 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.JSPs are the equivalent of Microsoft’s Active Server

Pages (ASP) technology and Zend’s PHP system.

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 12: OOSSE Week 7 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.

OOSSE Week 7Facts about JSPshttp://java.sun.com/products/jsp/index.htmlAll JSPs have a file extension of .jspJSP is meant to be easier than Servlets.A JSP page generates a Servlet (or more)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.

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 13: OOSSE Week 7 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.

OOSSE Week 7simpleguestlist.jsp<html><head><title>An Example of a Simple JSP Accessing a database

Model</title></head><body><h1>A Listing Of Guests</h1><br><br><%@ page import="java.sql.*" %><table border="2"><tr><th width="50%">Email</th><th WIDTH="25%">Firstname</th><th WIDTH="25%">Lastname</th></tr>Version 1.1 Nov 2008

Slide [email protected]/[email protected]

Page 14: OOSSE Week 7 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.

OOSSE Week 7<%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>

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 15: OOSSE Week 7 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.

OOSSE Week 7Kit requiredWhat do you need to develop and run JSPs?Up-to-date JDKTomcat HTTP serverWith database interaction we need a

database – we will use MSAccess for convenience

We could use mySQL or any other supported SQL-based database

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 16: OOSSE Week 7 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.

OOSSE Week 7Demo of a JSPThis example is a JSP which uses a DSN to

the GuestBook database Normally we prefer DSN-less connectionsThe application model is essentially a JSP

connecting to a database

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 17: OOSSE Week 7 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.

OOSSE Week 7JSP Translation process

Version 1.1 Nov 2008Slide [email protected]/[email protected]

.jsp file

(HTML interleaved

with Java)

HTTP Server

TOMCAT

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

Request: JSP translated

into a Servlet .java file and then

compiled into a Servlet ,class

Backend database, usually on

the server

Query for data content

Page 18: OOSSE Week 7 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.

OOSSE Week 7SimpleGuestList.jsp

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 19: OOSSE Week 7 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.

OOSSE Week 7SummaryWe 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

JSP demands some programming skills but is more and more seen as an integration technology with can dovetail with technologies such as XML

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 20: OOSSE Week 7 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.

OOSSE Week 7SummaryWe used an HTTP server which supports JSPWe highlighted the features of a JSP

A .jsp file is essentially HTML with Java code insertsWhen 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 .java file can be viewed via a text editor but MUST not be edited

The compilation is only done once - subsequent calls to the JSP use the already compiled .class file

Version 1.1 Nov 2008Slide [email protected]/[email protected]

Page 21: OOSSE Week 7 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.

OOSSE Week 7Mal’s E-Commercehttp://fcet5.fcet.staffs.ac.uk/modules/Applied_Computing/Level5/CE52302-5/2011-12/MalsE/MalsEcommerce.html

This is one of my sample E-Commerce sites that uses Mal’s E-Commerce shopping cart software

From the source code of the site you can see how it it configured to use Mal’s system

To use the software you must apply for an account and then it is a question of following the instructions given via the Mal’s website

Version 1.1 Nov 2008Slide [email protected]/[email protected]


Recommended