Computer Science E-259 XML with Java, Java Servlet, and JSP

Lecture 7: HTTP 1.1, JavaServer Pages 2.1, and Java Servlet 2.5 5 November 2007 David J. Malan [email protected]

1 Copyright © 2007, David J. Malan . All Rights Reserved.

Computer Science E-259 Last Time ƒ ƒ ƒ

Namespaces in XML 1.0 (Second Edition) SVG 1.1 XSL (XSL-FO) 1.1

2 Copyright © 2007, David J. Malan . All Rights Reserved.

Computer Science E-259 This Time ƒ ƒ ƒ ƒ ƒ

HTTP 1.1 n-Tier Enterprise Applications JavaServer Pages 2.1 Java Servlet 2.5 Project 3

3 Copyright © 2007, David J. Malan . All Rights Reserved.

HTTP 1.1 Overview ƒ

ƒ

Request Methods ƒ GET ƒ POST TCP Ports

Client

Server

4 Copyright © 2007, David J. Malan . All Rights Reserved.

HTTP 1.1 Cookies set-cookie cookies cookie NAME VALUE cookie-av

5

= = = = = = | | | | |

"Set-Cookie:" cookies 1#cookie NAME "=" VALUE *(";" cookie-av) attr value "Comment" "=" value "Domain" "=" value "Max-Age" "=" value "Path" "=" value "Secure" "Version" "=" 1*DIGIT%

Excerpted from RFC 2109: HTTP State Management Mechanism.

Copyright © 2007, David J. Malan . All Rights Reserved.

HTTP 1.1 Cookies

6

cookie

=

cookie-value cookie-version NAME VALUE path domain

= = = = = =

"Cookie:" cookie-version 1*((";" | ",") cookie-value) NAME "=" VALUE [";" path] [";" domain] "$Version" "=" value attr value "$Path" "=" value "$Domain" "=" value

Excerpted from RFC 2109: HTTP State Management Mechanism.

Copyright © 2007, David J. Malan . All Rights Reserved.

n-Tier Enterprise Applications n=2 ƒ ƒ

client tier ƒ presents data to user, gathers data from user server tier ƒ hosts application logic, databases, and data services

Client

Server

7 Copyright © 2007, David J. Malan . All Rights Reserved.

n-Tier Enterprise Applications n=3 ƒ ƒ ƒ

Client Tier ƒ presents data to user, gathers data from user Middle Tier ƒ hosts application logic Back-End Tier ƒ hosts databases and data services

Browser

Web Server

Email Server

8 Copyright © 2007, David J. Malan . All Rights Reserved.

n-Tier Enterprise Applications n=5

Browser

Web Server

Database server

Application Server

Email Server

9 Copyright © 2007, David J. Malan . All Rights Reserved.

n-Tier Enterprise Applications XML ƒ ƒ

ƒ ƒ

XML was originally targeted for data publication to the client The rationale was that the client software ƒ may know best how to display the data for this particular user ƒ could benefit from the more semantically meaningful and self-expressive capabilities of XML over HTML Very quickly, however, everyone started realizing the potential of XML on the server side as well Today, XML can be deployed at all tiers

10 Copyright © 2007, David J. Malan . All Rights Reserved.

n-Tier Enterprise Applications XML on the Client ƒ

ƒ

If the server communicates to the client self-describing, semantically tagged data in XML, then the client can ƒ do more intelligent rendering with the help of stylesheets (e.g., dynamic sorting, searching) ƒ present multiple views on the same data ƒ take some processing load off the server ƒ save many roundtrips to the server by caching data Clients can even communicate data to other clients in XML!

11 Copyright © 2007, David J. Malan . All Rights Reserved.

n-Tier Enterprise Applications XML in the Middle Tier ƒ

ƒ

Middle-tier applications often intercommunicate by exposing remote objects ƒ COM/DCOM objects expose COM interfaces but are bound to Microsoft platforms ƒ EJBs expose Java interfaces via RMI but only allow Java clients ƒ CORBA uses IDL interfaces and attempts to be platform-neutral Content aggregation via XML ƒ completely platform neutral ƒ easy to use ƒ easy to send over the network

12 Copyright © 2007, David J. Malan . All Rights Reserved.

n-Tier Enterprise Applications XML in the Middle Tier

Databases

New App

Legacy



ERP, Accounting, HR

Enterprise Data Dictionary

13 Copyright © 2007, David J. Malan . All Rights Reserved.

n-Tier Enterprise Applications XML in the Back-End Tier ƒ

ƒ

The backend tier usually consists of databases and data services, including ƒ relational databases ƒ CRM (customer relationship management) applications ƒ ERP (enterprise resource planning) applications ƒ other legacy applications The challenge is to enable middle-tier applications to access information from these data sources

14 Copyright © 2007, David J. Malan . All Rights Reserved.

n-Tier Enterprise Applications Typical J2EE Architecture

Computer PDA

Laptop

Client

Presentation

XML?

XML?

XML?

JSP/servlet

HTTP

JSP/servlet Web Server

Business Logic

XML?

XML?

EJB

EJB

RMI

EJB Server XML?

15

Data

XML?

JDBC

DB Copyright © 2007, David J. Malan . All Rights Reserved.

JavaServer Pages 2.1 The JavaServer Pages™ Technology

"JavaServer Pages™ is the Java™ 2 Platform, Enterprise Edition (J2EE) technology for building applications for generating dynamic web content, such as HTML, DHTML, XHTML and XML. JSP technology enables the easy authoring of web pages that create dynamic content with maximum power and flexibility."

16

Excerpted from JavaServer™ Pages Specification, Version 2.0.

Copyright © 2007, David J. Malan . All Rights Reserved.

JavaServer Pages 2.1 What is a JSP Page? “A JSP page is a textual document that describes how to create a response object from a request object for a given protocol. The processing of the JSP page may involve creating and/or using other objects.... HTTP is the default protocol for requests and responses. Additional request/response protocols may be supported by JSP containers.... The default request and response objects are of type HttpServletRequest and HttpServletResponse respectively.”

17

Excerpted from JavaServer™ Pages Specification, Version 2.0.

Copyright © 2007, David J. Malan . All Rights Reserved.

JavaServer Pages 2.1 hello, world <% out.print("hello, world"); %> <% out.print("hello, world"); %>

18 Copyright © 2007, David J. Malan . All Rights Reserved.

JavaServer Pages 2.1 hello, world ]]> ]]> <jsp:scriptlet> out.print("hello, world"); </jsp:scriptlet> out.print("hello, world");

19 Copyright © 2007, David J. Malan . All Rights Reserved.

Java Servlet 2.5 What is a Servlet?

“A servlet is a Java™ technology-based Web component, managed by a container, that generates dynamic content. Like other Javabased components, servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web server.”

20

Excerpted from Java™ Servlet Specification, Version 2.4.

Copyright © 2007, David J. Malan . All Rights Reserved.

Java Servlet 2.5 What is a Servlet Container?

“The servlet container is a part of a Web server or application server that provides the network services over which requests and responses are sent, decodes MIME-based requests, and formats MIME-based responses. A servlet container also contains and manages servlets through their lifecycle.”

21

Excerpted from Java™ Servlet Specification, Version 2.4.

Copyright © 2007, David J. Malan . All Rights Reserved.

Java Servlet 2.5 Java Servlet Containers

22

ƒ ƒ ƒ ƒ ƒ

Apache Tomcat BEA WebLogic Server IBM WebSphere Application Server JBoss Application Server Oracle Application Server

ƒ

Sun Java System Application Server Platform Edition

ƒ

...

Adapted from http://java.sun.com/j2ee/compatibility.html.

Copyright © 2007, David J. Malan . All Rights Reserved.

Java Servlet 2.5 Typical Sequence of Events 1. A client (e.g., a Web browser) accesses a Web server and makes an HTTP request. 2. The request is received by the Web server and handed off to the servlet container. The servlet container can be running in the same process as the host web server, in a different process on the same host, or on a different host from the web server for which it processes requests. 3. The servlet container determines which servlet to invoke based on the configuration of its servlets, and calls it with objects representing the request and response. 4. The servlet uses the request object to find out who the remote user is, what HTTP POST parameters may have been sent as part of this request, and other relevant data. The servlet performs whatever logic it was programmed with, and generates data to send back to the client. It sends this data back to the client via the response object. 5. Once the servlet has finished processing the request, the servlet container ensures that the response is properly flushed, and returns control back to the host Web server. 23

Excerpted from Java™ Servlet Specification, Version 2.4.

Copyright © 2007, David J. Malan . All Rights Reserved.

Java Servlet 2.5 hello, world

javax.servlet.* javax.servlet.http.*

24 Copyright © 2007, David J. Malan . All Rights Reserved.

Java Servlet 2.5 Sessions

25 Copyright © 2007, David J. Malan . All Rights Reserved.

Java Servlet 2.5 Synchronization

26 Copyright © 2007, David J. Malan . All Rights Reserved.

Project 3 Content Syndication Main Entry: syn·di·cate Pronunciation: 'sin-d&-"kAt Function: verb Inflected Form(s): -cat·ed; -cat·ing Date: 1882 transitive senses 1 : to subject to or manage as a syndicate 2 a : to sell (as a cartoon) to a syndicate or for publication in many newspapers or periodicals at once b : to sell (as a series of television programs) directly to local stations intransitive senses : to unite to form a syndicate - syn·di·ca·tion /"sin-d&-'kA-sh&n/ noun - syn·di·ca·tor /'sin-d&-"kA-t&r/ noun

27

Excerpted from Merriam-Webster OnLine, Copyright © 2007 by Merriam-Webster, Incorporated.

Copyright © 2007, David J. Malan . All Rights Reserved.

Project 3 Wahoo!

Computer

You Write! Client Tier

Login servlet

Prefs servlet

View servlet

webserver

Middle Tier UserManager

NewsProvider moreover.com

User DB

Back-End Tier

28 Copyright © 2007, David J. Malan . All Rights Reserved.

Next Time XQuery 1.0 and DTD ƒ ƒ

XQuery 1.0 DTD

29 Copyright © 2007, David J. Malan . All Rights Reserved.

Computer Science E-259 XML with Java, Java Servlet, and JSP

Lecture 7: HTTP 1.1, JavaServer Pages 2.1, and Java Servlet 2.5 5 November 2007 David J. Malan [email protected]

30 Copyright © 2007, David J. Malan . All Rights Reserved.

Computer Science E-259 - HUIT Sites Hosting

Nov 5, 2007 - 22. Copyright © 2007, David J. Malan . All Rights Reserved. Java Servlet 2.5. Java Servlet Containers. ▫ Apache Tomcat. ▫ BEA WebLogic Server. ▫ IBM WebSphere Application Server. ▫ JBoss Application Server. ▫ Oracle Application Server. ▫ Sun Java System Application Server ...

191KB Sizes 1 Downloads 194 Views

Recommend Documents

Computer Science E-259 - HUIT Sites Hosting
Nov 5, 2007 - All Rights Reserved. n-Tier Enterprise Applications. Typical J2EE Architecture. Client. Presentation. Business Logic. Data. Computer. Laptop.

Scamazon.com - HUIT Sites Hosting
Dec 20, 2007 - project4-8.0/ directory from the course's website to your local machine. .... If your account or system ain't so happy, feel free to contact.

Wahoo! - HUIT Sites Hosting
Windows machine, you should instead execute `catalina.bat run` (assuming "%CATALINA_HOME%\bin\" is in your. PATH); alternatively ... http://127.0.0.1:n/. 10 Although you needn't type "http://" to visit most websites with most browsers these days, you

Scamazon.com - HUIT Sites Hosting
Dec 20, 2007 - an “Access Key ID” for Amazon's Web Services immediately, .... Next, proceed to edit project4-8.0/conf/server.xml with your favorite text editor.

Wahoo! - HUIT Sites Hosting
If you opt to develop on a ..... 20 Know that, during the development of this project, you can update your Javadoc by executing ... new StreamSource(new java.io.

build.xml 1/2 - HUIT Sites Hosting
7: Of course, that port cannot already be in use. Nor can it. 8: be the same value you choose for the Connector element's port. 9: 10: Also be sure to set the value ...

build.xml 1/2 - HUIT Sites Hosting
5: Computer Science E-259. 6: .... description="remove class, log, runtime, temp, and work files">. 149: ... 12: Of course, that port cannot already be in use.

build.xml 1/2 - HUIT Sites Hosting
64: call.setTargetEndpointAddress(new java.net.URL(endpoint));. 65: call.setOperationName("processPO");. 66: 67: // invoke the service and return the (PO-ACK) response. 68: return (String) call.invoke(new Object [] { poXmlString });. 69: }. 70: catch

DiagServer.java 1/2 - HUIT Sites Hosting
12: * If you spawn the server on a port already in use, you will be informed. 13: * "Server failed to start: java.net.BindException: Permission denied". 14: * Note ...

SOAP 1.2 What - HUIT Sites Hosting
Apr 13, 2005 - XML with Java. Lecture 11: Web Services, SOAP 1.2, and WSDL 1.1 .... Distributed computing platforms allow programmatic components to ...

build.xml 1/1 - HUIT Sites Hosting
Login.java. 1/2 project3-8.0/src/cscie259/project3/wahoo/. 1: package cscie259.project3.wahoo;. 2: 3: import java.io.IOException;. 4: import java.io.PrintWriter;. 5: 6: import javax.servlet.ServletException;. 7: 8: import javax.servlet.http.HttpServl

Syllabus - HUIT Sites Hosting - Harvard University
Oct 15, 2007 - the form [email protected], where username is your FAS username. .... your plan at any point, provided you obtain the staff's approval for any modifications. ... Any of these texts should prove a valuable reference for.

Is Computer Science Science?
Apr 28, 2005 - ... granting CS degrees for 40 years. ... Computer science meets every criterion for being a science, but it has a ... The lexicographers offer two.

The Future of Computer Science - Cornell Computer Science
(Cornell University, Ithaca NY 14853, USA). Abstract ... Where should I go to college? ... search engine will provide a list of automobiles ranked according to the preferences, .... Rather, members of a community, such as a computer science.

Computer Science E-259 Lectures - Computer Science E-259: XML ...
Sep 17, 2007 - most important new technology development of the last two years." Michael Vizard ... applications: what are the tools and technologies necessary to put ... XML. When. ▫ The World Wide Web Consortium (W3C) formed an XML.

Computer Science E-259
Jan 7, 2008 - Yahoo! UI Library http://developer.yahoo.com/yui/ ..... how to program in JavaScript and PHP, how to configure. Apache and MySQL, how to ...

Computer Science E-259
Nov 19, 2007 - labeling the information content of diverse data sources .... .... ELEMENT article (url, headline_text, source, media_type, cluster,.

TEXTS IN COMPUTER SCIENCE
Java — Designed as a language to support mobile programs, Java has special .... We offer a few low-level coding hints that are helpful in building quality programs. ...... cheap in selecting your table size or else you will pay the price later.

Computer Science E-259
Oct 1, 2007 - DOCTYPE students SYSTEM "student.dtd">.