XML for E-commerce IV Helena Ahonen-Myka. In this part... n Some solutions for delivering dynamic content n Example of using XML.

Slides:



Advertisements
Similar presentations
CGI programming. Common Gateway Interface interface between web server and other programs (cgi scripts) information passed as environment variables passed.
Advertisements

M-V-C for web applications. Model for Web Applications model consists of data and system state database tables –persistent data session information –current.
1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
Java Server Pages (JSP)
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Java Servlet & JSP © copyright 2005 SNU OOPSLA Lab.
Server Side Programming Common Gateway Interface (CGI): Scripts generate Web pages or other files dynamically by processing form data and returning documents.
Introduction to Servlets Based on: Hall, Brown, Core Servlets and JavaServer Pages.
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
Python and Web Programming
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
Web programming for project students Dr Jim Briggs.
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
Server Side Programming Web Information Systems 2012.
Servlets Compiled by Dr. Billy B. L. Lim. Servlets Servlets are Java programs which are invoked to service client requests on a Web server. Servlets extend.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
SE-2840 Dr. Mark L. Hornick1 Java Servlet-based web apps Servlet Architecture.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Java Servlets. What Are Servlets? Basically, a java program that runs on the server Basically, a java program that runs on the server Creates dynamic.
Servlet and JSP Programming: An Introduction Spiros Papadimitriou
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Introduction Servlets and JSP Celsina Bignoli
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
1 Servlet How can a HTML page, displayed using a browser, cause a program on a server to be executed?
1 Understanding Cocoon2 Pankaj Kumar May 24, 2001 Web Services Organization HPMD, SSO, HP.
SDPL 2002Notes 7: Apache Cocoon1 7 XML Web Site Architecture Example: Apache Cocoon, a Web publishing architecture based on XML technology
Examples of Using Servlets and JSP Representation and Management of Data on the Internet.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
CSC 2720 Building Web Applications
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Java Servlets. Servlets When we run small Java programs within a browser these are referred to as Applets... And when we run small Java programs within.
Chapter 6 Server-side Programming: Java Servlets
1 CS122B: Projects in Databases and Web Applications Spring 2015 Notes 03: Web-App Architectures Professor Chen Li Department of Computer Science CS122B.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
Java Servlets and Java Server Pages Norman White Stern School of Business.
JSP Pages. What and Why of JSP? JSP = Java code imbedded in HTML or XML –Static portion of the page is HTML –Dynamic portion is Java Easy way to develop.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
Java Servlets and Java Server Pages
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
S ERVLETS Form Data 19-Mar-16. F ORM P ROCESSING You must have come across many situations when you need to pass some information from your browser to.
Apache Cocoon – XML Publishing Framework 데이터베이스 연구실 박사 1 학기 이 세영.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
Speaker Name Speaker Title Speaker Title Oracle Corporation Olivier Le Diouris Principal Product Manager Oracle Corporation Building Servlet and JSP Applications.
Introduction Servlets and JSP
Servlet Fudamentals.
JDBC & Servlet CSE 4504/6504 Lab.
Servlets and Java Server Pages
Presentation transcript:

XML for E-commerce IV Helena Ahonen-Myka

In this part... n Some solutions for delivering dynamic content n Example of using XML

Solutions for delivering dynamic content n CGI (e.g. Perl, PHP) n Java servlets n Java Server Pages (JSP) n Extensible Server Pages (XSP)

CGI n Server starts external programs using CGI interface (input, output, requests) n a new process is started and the program code is loaded each time a request occurs (even when simultaneous requests) n stateless n any programming languages: Perl, PHP are popular

Perl CGI package #!/usr/bin/perl use CGI qv(:standard); print header(), start_html(”Hello param($name)!”), h1(”Hello param($name)!”), end_html(); n Assume: name is a form field:

PHP #!/usr/local/bin/php > <?php echo ”Hello $name !”; ?>

Java servlets n Java programs that run on a web server and build web pages n each request handled by a thread (light) n only one copy of the code (for simultaneous requests) n maintaining a state easier

public class helloWWW extends HttpServlet { public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(”text/html”); printWriter out = response.getWriter(); out.println(” \n” + ” \n” + ” Hello” + request.getParameter(”name”) + ”! ” + ” \n” + ” Hello” + request.getParameter(”name”) + ”! \n” + ” ”); }}

Java Server Pages (JSP) n static HTML + dynamic parts n within the code, e.g. n JSP pages are converted to Java servlets (the first time the page is requested) and the servlet is compiled

Hello <% request.getParameter(”name”) %> Hello <% request.getParameter(”name”) %>

Extensible Server Pages (XSP) n XML pages with embedded logic n processing can be done before the styling and presentation is done n therefore the result can easily be used in further processing (cf. JSP is used to generate output) n and the logic is separated from presentation

<?xml-stylesheet href=”myStylesheet.xsl” type=”text/xsl”?> <xsp:page language=”java” xmlns:xsp= ” private static int numHits = 0; private synchronized int getNumHits() { return ++numHits;} Hit Counter I’ve been requested getNumHits() times.

Example n The Foobar Public Library n mytechbooks.com n customers of mytechbooks.com

The Foobar Public Library n suppliers can add new books that they are sending to the library n an HTML page with a form: <form method=”POST” action=” … Title: Publisher: …

addBooks.pl n a Perl CGI script: reads the data received from the user and produces XML data n each new entry is appended to an existing file

Writing an XML file $bookFile = ”/home/foobar/books/books.txt”; use CGI; $query = new CGI; $title = $query->param(’title’); $publisher = $query->(’publ’); … if (open(FILE, ”>>”. $bookFile)) { print FILE ” \n”; print FILE ” \n; … print FILE ” \n\n”;

Notes: n Only an XML fragment is generated: no declaration, no root element

n Some other portion of the library’s application periodically reads the XML data and updates the library’s catalog: this part also removes the entries from the list of new entries n providing a listing of new available books: add an XML declaration etc.

supplyBooks.pl $bookFile = ”/home/foobar/books/books.txt” open(FILE, $bookFILE) || die ”Could’t open $bookFile.”; print ”Content-type: text/plain\n\n”; print ” \n”; while ( ) { print ”$_”; } print ” \n”; close(FILE);

mytechbooks.com n can make HTTP requests (supplyBooks.pl) and receives a list of books in XML n needs a listing of new technical books on their own Web page n wants to advertise (push technology)

Filtering the XML data n only computer-related books are to be included (Foobar Library has several other subjects as well) n subject information is an attribute of the book element n filter out all the books whose subject is not ”Computers”

computerBooks.xsl … <xsl:apply-templates />

XSL stylesheet: book Author: Publisher: Pages: Price: /servlets/BuyBookServlet?isbn=

XSLT from a servlet import... public class ListBooksServlet extends HttpServlet { private static final String hostname=”foobar.com”; private static final int portNumber = 80; private static final String file =”/cgi/supplyBooks.pl”; private static final String stylesheet = ”/home/…/computerBooks.xsl”; public void service(HttpServletRequest req, HttpServletResponse res) throws … { res.setContentType(”text/html”); URL getBooksURL = new URL(”http”,hostname,portNumber,file); InputStream in = getBooksURL.openStream(); // transform XML into HTML }}

Notes: n Servlet requests the Foobar Public Library’s application (supplyBooks.pl) through an HTTP request, and gets the XML response in an InputStream n this stream is used as a parameter to the XSLT processor, as well as the XSL stylesheet defined as a constant in the servlet

Invoking transformations n There is current no general API that specifies how XSLT transformations can occur programmatically: each processor vendor should have classes that allow a transformation to be invoked from Java code

Invoking transformations n Apache Xalan: XSLTProcessor class in the org.apache.xalan.xslt package n parameters: the XML file to process, the stylesheet to apply, and output stream (servlet output stream can be used)

… URL getBooksURL = new URL (”http”, hostname, portNumber, file); InputStream in = getBooksURL.openStream(); try { XSLTProcessor processor = XSLTProcessorFactory.getProcessor(); processor.process(new XSLTInputSource(in), new XSLTInputSource ( new FileInputStream(stylesheet)), new XSLTResultTarget( res.getOutputStream())); } catch (Exception e) {…} }

Push vs. pull n Pull: the user writes an URL or follows a link, or an application makes an HTTP request n Push: data is delivered to the user without the user’s active request; e.g. which new items are available, special offers...

Personalized start pages and RSS n Personalized start pages: e.g. Netscape’s My Netscape and Yahoo’s My Yahoo n Rich Site Summary (RSS): an XML application, which defines channels n a channel provides quick info about e.g. a company’s products (for display in a portal-style framework)

RSS channel n title of the channel n description of the channel n image or logo n items, each item may contain title, description and hyperlink

… in our example n mytechbooks.com would like to create an RSS channel that provides new book listings: interested clients can jump directly to buying an item n a channel is registered with Netscape Netcenter n Netcenter will automatically update RSS channel content

<!DOCTYPE rss PUBLIC ”-//Netscape Communications//DTD RSS 0.91//EN” ” mytechbooks.com New Listings Your online source for technical material, computers, and computing books! en-us …

Java Servlet Programming This book is a superb introduction to Java servlets and their various communications mechanisms.

Transformation into RSS n an XSLT transformation can transform the book elements to item elements: n book -> item n title -> title n saleDetails/isbn -> link (isbn as param.) n description -> description

Validating the RSS channel n validate.tmpl n there are some constraints that cannot be enforced by the DTD n RSS channel can be a servlet, CGI script, a static file...

Registering the channel n The channel is published to Netcenter (or other service provider) n n once the valid channel is accepted, instructions how to add the channel to a web page is sent by

Use n button or link is added to the mytechbooks.com web page: ”Add this site to My Netscape” n inclusion in the Netscape Open Directory

Not restricted to Netscape n The same RSS format can (and is) used in different applications n format is simple and generic: suitable for many purposes