81
1106174542 Richard West 1 Deploying Dynamic Sites Using Page Compilation, JavaServer Pages TM Software and an Object Oriented Database Richard West Technical Director, Diverse Solutions & Virtual Web Dynamics

Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 1

Deploying Dynamic Sites Using PageCompilation, JavaServer Pages TM Software

and an Object Oriented Database

Richard WestTechnical Director, Diverse Solutions & Virtual Web Dynamics

Page 2: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 2

Richard West

Technical Director

Diverse Solutions - divsol.com.au- The technical company

[email protected]

Virtual Web Dynamics - vwebd.com- The sales / marketing company

[email protected]

Page 3: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 3

Introduction

This presentation will cover the principles,basic design and code needed in order touse the Jigsaw Web Server and an Object-Oriented Database (Object Design’s PSEPro) to construct sites with dynamiccontent using both Page Compilation andJavaServer Pages TM software (JSP)

NOTE :

This was to be on Java Web Server TM

Software, but since this no longerexists :-(, we’ll use Jigsaw :-)

Page 4: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 4

Assumptions

• You Know Java TM Technology!

• Understand:– The Web, its protocols and Web Servers– Basic Servlet Interface and concepts– Forms Handling– Persistence and why we’d want it on a web site

Page 5: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 5

Metaview

• Part 1—The Basics– Jigsaw, PSE Pro & Page Compilation– Configuring Jigsaw and your development tool– Basic Page Compilation with Global Sessions

BREAK

• Part 2—Advanced Topics and Discussion– Advanced Page Compilation with Local

Sessions and Threading– General Utilities– Using JavaServer Pages TM software

with PSE Pro– Discussion

Page 6: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 6

Overview—Part 1The Basics

• Jigsaw Web Server Software and installation

• Brief overview of OODB’s and PSE Pro

• Page Compilation under Jigsaw

• Demonstration—Jigsaw andPage Compilation

• Configuring Jigsaw and your DevelopmentTool for PageCompilation and PSE Pro

Page 7: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 7

Overview—Part 1The Basics (Cont.)

• Simple Persistent Page Compilation

• Extending GeneratedFrame for PageCompilation

• Demonstration—Jigsaw and PageCompilation with Persistence

• Questions

• Break

Page 8: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 8

Jigsaw Web ServerSoftware and Installation

– Get Jigsaw: www.w3c.org/Jigsaw– Add VirtualHost Resource– Add Frame– VirtualHostFrame– Set Followup to root– Add PassDirectory– Configure Id as web server name– You Now have a virtual host!– Add HTTPFrame to your host– Set Index– Configure Root Name to virtual

Page 9: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 9

Add VirtualHost Resource

Page 10: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 10

Add Frame

Page 11: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 11

VirtualHostFrame

Page 12: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 12

Set Followup to root

Page 13: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 13

Add PassDirector y

Page 14: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 14

Confi gure Identifier asWeb Server Name

Page 15: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 15

You Now Have a Virtual Host!

Page 16: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 16

Add HTTPFrame to Your Host

Page 17: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 17

Set Index

Page 18: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 18

Confi gure Root Name to virtual

Page 19: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 19

Brief Overview ofOODB’s and PSE Pro

• Why an OODB?—pros and cons

• Basic principles

• Object Design’s PSE Pro– www.odi.com/psepro

• Others on the Market

Page 20: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 20

3URV

6WRUHV REMHFWV LQ QDWLYH IRUPDW

([WUHPHO\ )DVW 7UDYHUVDO

1R µ,PSHGDQFH 0LVPDWFK¶

&RQV

2QO\ QRQ -DYD 7HFKQRORJ\22'%¶V VKRXOG KDYH SODWIRUPSRUWDELOLW\ SUREOHPV

'RHVQ¶W VWRUH REMHFWV LQ DUHODWLRQDO WDEOH ! WRRO DQGWUDQVIHU SUREOHPV

22'% VWDQGDUGV UHODWLYHO\LPPDWXUH

Why an OODB?—Pros and Cons

Page 21: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 21

Basic Principles

3URJUDP'DWDEDVH

22'%�3URJH�J��36(�3UR

<RXU�2EMHFWV

'%5RRW

Page 22: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 22

Object Desi gn’s PSE Pro

• Certified 100% Pure Java™

• Small Footprint

• Mature Product (Release 3.0)

• Migration Path (to ObjectStore)

• Easy To Use

• Can make 3rd Party Code Persistent!!!

Page 23: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 23

Others on the Market

• Jeevan

• Poet

• O2

• Jasmine

• Academic

• See CetusLinks for more info

www.cetus-links.org/oo_db_systems_1.html

Page 24: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 24

What Is Pa ge Compilation?

Source

HTML &Java or JSP

Page or JSPCompiler

Source

Servletin Java Java

Compiler

.classfile

WebServer

Servlet

Served /executed byBrowser

Request

Result of Servlet Execution

Page 25: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 25

Page Compilation Under Ji gsaw

• Configuring couldn’t be easier!

• Thanks to Dynamic Loading—just use a.jhtml page!!!

Page 26: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 26

Page Compile Source File

<html> <head> <title>Page Compilation Test</title> </head> <body> <h1>Counter</h1> <ul> <java> for (int i = 1; i <= 10; i++) { out.println ("<li> item #" + i); } </java> </ul> </body></html>

Page 27: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 27

Compiled Pa ge

public class test extendsorg.w3c.jigsaw.pagecompile.GeneratedFrame { protected void get(org.w3c.jigsaw.http.Request request, org.w3c.jigsaw.http.Reply reply, org.w3c.jigsaw.pagecompile.PageCompileOutputStream out) throws java.io.IOException { org.w3c.jigsaw.pagecompile.PageCompileFile _file = new org.w3c.jigsaw.pagecompile.PageCompileFile(

"E:\\Java\\Jigsaw\\Jigsaw\\WWW\\test.jhtml"); _file.writeBytes(0,118,out);

for (int i = 1; i < 10; i++) { out.println ("<li> item #" + i); } _file.writeBytes(235,268,out); }}

Page 28: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 28

Demonstration

Jigsaw and Page Compilation

Page 29: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 29

Confi gurin g Jigsaw for Pa geCompilation and PSE Pro

• Jigsaw Batch File: @echo off

java %1 %2 %3 %4 %5 %6 %7 %8 %9 -classpath%JIG_HOME%\classes;%JIG_HOME%\classes\jigsaw.zip;%JSDK_HOME%\servlet.jar;%CLASSPATH%org.w3c.jigsaw.Main -root %JIG_HOME%\Jigsaw

• Jigsaw Admin Batch File: @echo off

java -classpath%JIG_HOME%\classes\jigadmin.jar;%JIG_HOME%\classes\jigsaw.zip org.w3c.jigadmin.Main -root%JIG_HOME%\Jigsaw http://tao:8009

Page 30: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 30

Confi gurin g FreeBuilder forPage Compilation and PSE Pro

CLASS PATH : E:\Java\Jigsaw\classes\jigsaw.zip;E:\Java\jsdk2.1\servlet.jar;E:\ODI\PSEPROJ3\pro.jar

CLASS OUTPUT PATH : E:\Java\Jigsaw\classes

Page 31: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 31

Simple PersistentPage Compilation—1

<java type=import>import COM.odi.*;</java><java>/* A comment that doesn't appear in thegenerated page! */</java><html> <head> <title>Persistent DB Test</title> </head> <body> <h1>Counter</h1> <ul> <java> // *** NOTE THIS POINT *** try { // Matched on 3 Session.create(null, null).join(); Database db = null;

. . .

Page 32: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 32

Simple PersistentPage Compilation—2

try { db = Database.open("test.odb", ObjectStore.OPEN_UPDATE); } catch (DatabaseNotFoundException dbnfe) { db = Database.create("test.odb", ObjectStore.ALL_READ | ObjectStore.ALL_WRITE); } Transaction tr = Transaction.begin(ObjectStore.UPDATE); Integer count = null; try { count = (Integer)db.getRoot("Count"); } catch (DatabaseRootNotFoundException dbrnfe) { count = new Integer(1); db.createRoot("Count", count);} . . .

Page 33: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 33

Simple PersistentPage Compilation—3

for (int i = 1; i <= count.intValue(); i++) { out.println ("<li> item #" + i); } db.setRoot("Count", new Integer(count.intValue()+1)); tr.commit(); db.close(); } finally { // Matches try from 1 Session.getCurrent().terminate(); } </java> // *** NOTE THIS POINT *** </ul> </body></html>

DONE!

Page 34: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 34

Demonstration

Jigsaw and Pa ge Compilation with Persistence

Page 35: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 35

Extendin g GeneratedFramefor Pa ge Compilation

<java type=import>import Test.PLib;</java><java type=extends>Test.PLib</java>

. . .

<java> // *** NOTE THIS POINT *** joinSession(); Transaction tr = Transaction.begin( ObjectStore.UPDATE); Integer count = (Integer)db.getRoot("Count"); count = new Integer(count.intValue()+1); for (int i = 1; i <= count.intValue(); i++) { out.println ("<li> item #" + i); } db.setRoot("Count", count); tr.commit(); leaveSession();</java> // *** NOTE THIS POINT ***

Page 36: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 36

The Librar y—1

package Test;import java.util.Properties;import org.w3c.jigsaw.pagecompile.GeneratedFrame;import COM.odi.*;public abstract class PLib extends GeneratedFrame { protected static Database db = null; private static final String dbName = “test.odb", rootName = "Count"; public PLib() { } public static void joinSession() { Session.getGlobal().join(); } public static void leaveSession() { Session.getCurrent().leave(); } // Static initialiser goes here!} // - see next slide

Page 37: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 37

The Librar y—2

static { // Goes into previous slide Properties props = System.getProperties(); props.put("COM.odi.useDatabaseLocking", "false"); Session global = Session.createGlobal(null,props); try { db = Database.open(dbName, ObjectStore.OPEN_UPDATE); } catch (DatabaseNotFoundException dbnfe) { db = Database.create(dbName, ObjectStore.ALL_READ | ObjectStore.ALL_WRITE); Transaction trans = Transaction.begin(ObjectStore.UPDATE); db.createRoot(rootName, new Integer(0)); trans.commit(); } global.leave();}

Page 38: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 38

Questions & Break

Page 39: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 39

Overview Part 2—Advanced Topics & Discussion

• Local Sessions

• Helper Classes for Session Management

• General Utilities

• Configuring Jigsaw for JavaServerPages TM software (JSP)

• The Counter Bean

• Using Persistent JSP

• Questions, Wrap Up & Discussions

Page 40: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 40

Local Sessions and Utilities

• Global Sessions—fine for extremelysimple systems (i.e. demos)

• For Serious Threading, use Sessions» Update Library Code

• Need some ‘helper utilities’ to parsethe query string

Page 41: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 41

The Local Librar y—1

package Test;import java.util.Properties;import org.w3c.jigsaw.pagecompile.GeneratedFrame;import COM.odi.*;public abstract class PLib extends GeneratedFrame { protected static Database db = null; protected static Session sess = null ; private static final String dbName = “test.odb", rootName = ”Count"; private static final Object rootInit = new Integer(0); public PLib() { } public static void joinSession() { sess.join(); } public static void leaveSession() { sess.leave(); } // Static initialiser goes after here!} // - see next slide

Page 42: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 42

The Local Librar y—2

static { // Goes into previous slide Properties props = System.getProperties(); props.put("COM.odi.useDatabaseLocking", "false"); Session sess = Session.create(null,props); sess.join(); try { db = Database.open(dbName, ObjectStore.OPEN_UPDATE); } catch (DatabaseNotFoundException dbnfe) { db = Database.create(dbName, ObjectStore.ALL_READ | ObjectStore.ALL_WRITE); Transaction trans = Transaction.begin(ObjectStore.UPDATE); db.createRoot(rootName, new Integer(0)); trans.commit(); } sess.leave();}

Page 43: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 43

General Utilities

package Test;import org.w3c.jigsaw.http.Request;import javax.servlet.http.HttpUtils;import java.util.Hashtable;public class PUtil{ public PUtil(Request req) { parms = HttpUtils.parseQueryString( req.getQueryString()); } public String getVal(String key) { String[] vals = (String[])parms.get(key); if (vals != null) return vals[0]; else return null; } private Hashtable parms = null;}

Page 44: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 44

Site Structure

• Index page– Output Page : plotest.jhtml

• Page compilation Library Output TEST– Input Page : plitest.jhtml

• Page compilation Library Input TEST

• Input Processor : doPlitest.jhtml

Page 45: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 45

plotest. jhtml

<java type=import>import COM.odi.*;</java><java type=import>import Test.PLib;</java><java type=extends>Test.PLib</java><html> <head> <title>Persistent DB Test</title> </head> <body> <java> joinSession(); Transaction tr = Transaction.begin( ObjectStore.READONLY); Integer count = (Integer)db.getRoot("Count"); out.println ("<H1>Current Number : " + count+"</H1>"); tr.commit(); leaveSession(); </java> <a href="/plitest.jhtml">Change Counter</a> </body></html>

Page 46: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 46

plitest. jhtml

<java type=import>import COM.odi.*;</java><java type=import>import Test.PLib;</java><java type=extends>Test.PLib</java><html> <head><title>Persistent DB Input Test</title></head><body> <java> joinSession(); Transaction tr = Transaction.begin(ObjectStore.READONLY); Integer count = (Integer)db.getRoot("Count");</java> <form action="/doPlitest.jhtml" method="GET” enctype="application/x-www-form-urlencoded"> Enter New Current Number : <java> out.println("<input type=\"TEXT\" name=\"Count\” value= \""+count+"\"size=\"25\">"); </java> <input type="SUBMIT" name="Submit" VALUE="Submit"> </form> <H1>OR</H1> <a href="/plotest.jhtml">Current Value of Counter</a><java> tr.commit(); leaveSession(); </java> </body></html>

Page 47: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 47

doPlitest. jhtml—1

<java type=import>import COM.odi.*;</java><java type=import>import Test.*;</java><java type=extends>Test.PLib</java><html> <head><title>Persistent DB Test</title></head> <body> <java> PUtil pu = new PUtil(request); String count = pu.getVal("Count"); Integer newCount = null; try { newCount = new Integer(count); joinSession(); Transaction tr = Transaction.begin(ObjectStore.UPDATE); Integer oldCount = (Integer)db.getRoot("Count"); db.setRoot("Count", newCount); tr.commit(); leaveSession(); </java>

Page 48: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 48

doPlitest. jhtml—2

<H1>Change Successful!</H1> The number <java type=print>oldCount</java> has been sucessfully changed to <java type=print>newCount</java>. <P> Can <a href="/plotest.jhtml">Examine Current Value of Counter</a> or <a href="/plitest.jhtml">Change Current Value of Counter</a>. <java> } catch (NumberFormatException nfe) { </java> <H1>ERROR - Bad Number Format!</H1> Your number <java type=print>newCount</java> is not of the correct format. Please <a href="/plitest.jhtml">Go Back</a> and try again. <java> } </java> </body></html>

Page 49: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 49

Demonstration

Input and Output to an Ob jectDatabase usin g Forms with

Page Compilation

Page 50: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 50

Settin g Up Ji gsaw for JSP

– Get GNU JSP—http://www.xs4all.nl/~vincentp/gnujsp/

– Add JSP Servlet Resource– Add JSP ServletWrapper– Set Servlet Wrapper class– Add repository property to JSPServlet– Configured JSPServlet– Add Resource– Add jsp-indexer

Page 51: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 51

Settin g Up Ji gsaw for JSP (Cont.)

– Add Resource to jsp-indexer– Configure FileResource for jsp-indexer– Add Frame to jsp-indexer– Add ServletMapperFrame to jsp-indexer– Configure ServletMapperFrame– Now, the way it works– Add Resource to default Indexer– Set up jsp extension for default

Page 52: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 52

Add JSPServlet Resource

Page 53: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 53

Add JSP ServletWrapper

Page 54: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 54

Set Servlet Wrapper Class

Page 55: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 55

Add Repositor yPropert y to JSPServlet

Page 56: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 56

Confi gured JSPServlet

Page 57: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 57

Add Resource

Page 58: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 58

Add jsp-indexer

Page 59: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 59

Add Resource to jsp-indexer

Page 60: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 60

Confi gure FileResourcefor jsp-indexer

Page 61: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 61

Add Frame to jsp-indexer

Page 62: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 62

Add ServletMapperFrameto jsp-indexer

Page 63: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 63

Confi gure ServletMapperFrame

Page 64: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 64

Now, “The Wa y It Works”!

Page 65: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 65

Add Resource to Default Indexer

Page 66: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 66

Set Up jsp Extension for Default

Page 67: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 67

Finally, a JavaBeans™ Architecture-Based Component and JSP!

• Not necessarily optimal structurefor performance

• JSP Spec on GNU JSP 0.99 basedaround JSP 0.92 which is quite differentto JSP 1.0!

Page 68: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 68

Counter. java—Definition and Constructor

package Test;import java.util.Properties;import COM.odi.*;public class Counter{ protected static Database db = null; protected static Session sess = null; private static final String dbName = "test.odb", rootName = "Test"; private static final Object rootInit = new Integer(0); static { // Set up local Session with no Locking Properties props = System.getProperties(); props.put("COM.odi.useDatabaseLocking", "false"); sess = Session.create(null,props); sess.join();

Page 69: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 69

Counter. java—Constructors

try { db = Database.open(dbName, ObjectStore.OPEN_UPDATE); } catch (DatabaseNotFoundException dbnfe) { db = Database.create(dbName, ObjectStore.ALL_READ | ObjectStore.ALL_WRITE); Transaction trans = Transaction.begin(ObjectStore.UPDATE); db.createRoot(rootName, rootInit); trans.commit(); } sess.leave(); } public Counter() { }

Page 70: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 70

Counter. java—Get Accessor

public int getCount() { joinSession(); Transaction tr = Transaction.begin(ObjectStore.READONLY); Integer count = (Integer)db.getRoot("Count"); int counti = count.intValue(); tr.commit(); leaveSession(); return counti; }

Page 71: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 71

Counter. java—Set Accessorand Session Methods

public void setCount(int newCounti) { Integer newCount = new Integer(newCounti); joinSession(); Transaction tr =

Transaction.begin(ObjectStore.UPDATE); Integer oldCount = (Integer)db.getRoot("Count"); // Put counter back, commit & leave db.setRoot("Count", newCount); tr.commit(); leaveSession(); } protected static void joinSession() { sess.join(); } protected static void leaveSession() { sess.leave(); }}

Page 72: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 72

Site Structure

• Index page– Output Page: botest.jsp

• Bean Output TEST– Input Page: bitest.jsp

• Bean Input TEST

• Input Processor: doBitest.jhtml

Page 73: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 73

botest. jsp

<%@ import="Test.Counter" %>

<html>

<head>

<title>Persistent DB Test</title>

</head>

<body>

<H1>Current Number :

<BEAN name="Counter" type="Test.Counter"></BEAN>

<%= Counter.getCount() %>

</H1>

<a href="/bitest.jsp">Change Value of Counter</a>

</body>

</html>

Page 74: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 74

bitest. jsp

<%@ import="Test.Counter" %><html> <head> <title>Persistent DB Input Test</title> </head><body> <form action="/doBitest.jsp" method="GET” enctype="application/x-www-form-urlencoded"> Enter New Current Number : <BEAN name="Counter" type="Test.Counter"></BEAN> <% out.println("<input type=\"TEXT\" name=\"Count\” value=\""+Counter.getCount()+"\" size=\"25\">");%> <input type="SUBMIT" name="Submit" VALUE="Submit"> </form> <H1>OR</H1> <a href="/botest.jsp">Current Value of Counter</a></body></html>

Page 75: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 75

doBitest. jhtml—1

<%@ import="Test.Counter" %><html> <head> <title>Persistent DB Test</title> </head> <body> <BEAN name="Counter" type="Test.Counter"></BEAN> <% String count = request.getParameter("Count"); Integer newCount = null; try { int oldCount = Counter.getCount(); // Parse New Count newCount = new Integer(count); Counter.setCount(newCount.intValue()); %>

Page 76: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 76

doBitest. jhtml—2

<H1>Change Successful!</H1>

The number <%= oldCount %> has been sucessfully

changed to <%= newCount %>. <P> You can now

<a href="/botest.jsp">Examine Counter</a> or

<a href="/bitest.jsp">Change Counter</a>.

<% } catch (NumberFormatException nfe) { %>

<H1>ERROR - Bad Number Format!</H1> Your number <%= count %> is not of the correct format.

Please <a href="/bitest.jsp">Go Back</a> and try again.

<% } %>

</body>

</html>

Page 77: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 77

Input and output to an Ob jectDatabase usin g forms with

JavaServer Pa gesTM software (JSP)

Demonstration

Page 78: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 78

Real World Applications

• MoDelta

– Written in 9 person-months– All JavaTM technology based– HTML 3.2 and up compatible– Fast! —runs on a UltraTM 1 platform from Sun!!!– http://www.vwebd.com

• Brief Tour

Page 79: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 79

Thanks

• The Java Web Server™ software product team– Thanks for the memories

• The Jigsaw Web Server team– Thanks for the future!

• GNUJSP

• Freebuilder—www.freebuilder.com

• Sun—Cool Technology and the JavaOne SM

conference!

• YOU—Have fun and use persistent objects ‘Au-Naturale’!!!

Page 80: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 80

Wrap Up

Questions and Discussion

Page 81: Deploying Dynamic Sites Using Page Compilation, JavaServer ...read.pudn.com/downloads95/ebook/385578/JavaServer Pages Software and... · Deploying Dynamic Sites Using Page Compilation,

1106174542 Richard West 81