ExampleExample
Student Record ApplicationStudent Record Application
EnvironmentEnvironment Run environment: JDK 1.4Run environment: JDK 1.4
Web server: TOMCAT as JSP containerWeb server: TOMCAT as JSP container
Application Server: pure Java ClassApplication Server: pure Java Class
Database: Oracle + JDBC driverDatabase: Oracle + JDBC driver
Development toolDevelopment tool NetBeans IDE 3.5.1NetBeans IDE 3.5.1
ANT+NotepadANT+Notepad
TomcatTomcat
Tomcat is a Servlet/JSP containerTomcat is a Servlet/JSP container
Tomcat implements the Servlet and Tomcat implements the Servlet and JavaServer Pages specifications from JavaServer Pages specifications from Java Software Java Software
J D K
T O M C A TJ av aC las s
O R A C L EB ro swe r
Architecture of Student Record Architecture of Student Record applicationapplication
Development work flowDevelopment work flowL o g ic A n a lys is
L o g ic D e s ig n
C o d e
P re p a re D a ta b a s e
C o nfig ueA pplic a tio n
D e plo yA pplic a tio n
R u n A p p lic a tio n
Logic analysisLogic analysis
Under the support of Rational XDE
Student
+ id+ firstname+ surname
+ add ( )+ modify ( )+ delete ( )+ get ( )
Logic designLogic design
Server Side: Servlet + pure java class Server Side: Servlet + pure java class
Client Side: JSP Client Side: JSP
Logical Architecture of Server Logical Architecture of Server Side Side
Under the support of Rational XDE
Design on J2EE framework
«JavaInterface»ServletContextListener
+ contextInitialized ( )+ contextDestroyed ( )
«JavaInterface»ContextListener
Student
+ id+ firstname+ surname
+ getID ( )+ getFirstname ( )+ getSurname ( )+ getFullname ( )+ getFullstudents ( )
StudentsDB
+ connection+ connectionFree+ Students
+ addStudent ( )+ deleteStudent ( )+ modifyStudent ( )+ getStudent ( )+ getStudents ( )+ getConnection ( )+ releaseConnection ( )+ close ( )
- theStudentsDB
0..1
- theStudent
0..1
ContextListenerContextListener
<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?><!DOCTYPE web-app<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN“PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN“ "http://java.sun.com/dtd/web-app_2_3.dtd">"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app><web-app>
<description>Oracle Test App</description><description>Oracle Test App</description> <listener><listener> <listener-class>StudentPackage.contextlisenter</listener-class><listener-class>StudentPackage.contextlisenter</listener-class> </listener></listener>
</web-app></web-app>
Web.xmlWeb.xml
JSP Logical Architecture of Client JSP Logical Architecture of Client Side Side
Hom e.js p
R e q u e s tD e le te.js p
D o D e le te.js p
R e q u e s tA d d.js p
R e q u e s tM o d ify.js p
D o A d d.js p
D o M o d ify.js p
JSPJSP
H o m e .js p
R e qu e s tD e le te.js p
D oD e le te.js p
R e qu e s tA dd.js p
R e qu e s tM odi fy.js p
D oA dd.js p
D oM odi fy.js p
de l e teadd m o di fy
c o nt i nue c o nt i nue
c o nt i nuec o nt i nuec o nt i nue
c o nt i nue
abo r tabo r t abo r t
E n try P o in t
Student Record Application Run Student Record Application Run CycleCycle
Install or Start StudentRecord Application
Call up JSP
Stop StudentRecord application
S tud entR ec o rdis initialized
C o n te x tL is te n e r.c o ntextInitialized ( )
C r e ate an i ns tanc e o fStude nts D B
S tu d e n ts D B .c o ns truc to r( )
c o nne c t i o n us i ng the jdbc /o r ac l e D ataSo ur c eto Ac c e s s D atabas e vi a
J D B C D r i ve r , U R L , us e r nam e and pas s o w r d
o ra c le .jd b c .d riv e r.O ra c le D riv e r
O ra c le D a ta b a s e
Sto r eStude nts D B i ns tanc ei n Se r vl e t Attr i bute
"Stude nts D B "" S tu d e n ts D B "
S e rv le t A ttrib u te(S tud ent)
Install or Start StudentRecord Application
Contextlistener start an Contextlistener start an ApplicationApplication
public void contextInitialized(ServletContextEvent sce) {public void contextInitialized(ServletContextEvent sce) { ServletContext sc= sce.getServletContext();ServletContext sc= sce.getServletContext(); trytry {{ StudentPackage.StudentDB studentdb= new StudentPackage.StudentDB studentdb= new
StudentPackage.StudentDB();StudentPackage.StudentDB(); sc.setAttribute ("studentdb", studentdb);sc.setAttribute ("studentdb", studentdb); }} catch (Exception e)catch (Exception e) {{ sc.log ("Couldn't create database attribute: " + sc.log ("Couldn't create database attribute: " +
e.getMessage ());e.getMessage ()); } } }// end of public void contextInitialized(ServletContextEvent e)}// end of public void contextInitialized(ServletContextEvent e)
c al l upHom e.js p
J SP i s c o m pl i e dand e xe c ute d c o m pl ie d
H o m e .jspR e tr i ve
Stude nts D B fr o mSe r vl e t Attr i bute
"Stude nts D B "
" S tu d e n ts D B "S e rv le t A ttrib u te
(S tu d e n t)
Aqui r e a i ns tanc e o fStude nts D B
S tu d en ts D B
R e ad s tude nt r e c o r d
o ra c le .jd b c .d riv e r.O ra c le D riv e r
O racle
R e tur n s tude nt r e c o r d
R e tur n s tude nt r e c o r d
D i s pl ay s tude nt r e c o r d
Call up Home.jsp
Use StudentDB instanceUse StudentDB instance
<%<% StudentPackage.StudentDB studentdb= StudentPackage.StudentDB studentdb=
(StudentPackage.StudentDB) (StudentPackage.StudentDB) application.getAttribute("studentdb");application.getAttribute("studentdb");
Collection students = studentdb.getStudents();Collection students = studentdb.getStudents();
%>%>
Home.jspHome.jsp
S to pS tu d e n tR e c o rd
C o nte xtL is te ne r.c o nte xtD e s tro ye d( )
" S tu d en tsD B "S erv le t A ttrib u te
(S tu d en t)
R e m o v eS tu d e n ts D B
in S e rv le t A ttrib u te" S tu d e n ts D B "
R e triv eS tu d e n ts D B fro mS e rv le t A ttrib u te
" S tu d e n ts D B " C o m pl i e dJ AVA Se r ve r
P ag e s
A c q u ire a in s tan c e o fS tu d e n ts D B
S tude nts D B
C lo s e D atab as e
O ra c le
o ra c le .jdbc .drive r.O ra c le D rive r
D e s to ry in s tan c e o fS tu d e n ts D B
Stop Student Record Application
Contextlistener stop an Contextlistener stop an ApplicationApplication
public void contextDestroyed(ServletContextEvent public void contextDestroyed(ServletContextEvent sce) {sce) {
ServletContext sc = sce.getServletContext ();ServletContext sc = sce.getServletContext (); StudentPackage.StudentDB studentdb = StudentPackage.StudentDB studentdb =
(StudentPackage.StudentDB) (StudentPackage.StudentDB) sc.getAttribute("studentdb");sc.getAttribute("studentdb");
studentdb.close();studentdb.close(); sc.removeAttribute ("studentdb");sc.removeAttribute ("studentdb"); }}
Prepare DatabasePrepare Database
Create tableCreate tableCREATE TABLE STUDENTDBCREATE TABLE STUDENTDB
( ID NUMBER(10) NOT NULL PRIMARY KEY, ( ID NUMBER(10) NOT NULL PRIMARY KEY,
FIRSTNAME VARCHAR2(30) NOT NULL,FIRSTNAME VARCHAR2(30) NOT NULL,
SURNAME VARCHAR2(30) NOT NULLSURNAME VARCHAR2(30) NOT NULL
););
Insert student recordInsert student recordinsert into studentdb (id, firstname, surname) insert into studentdb (id, firstname, surname)
values (101,'Emma','Dean');values (101,'Emma','Dean');
Configure ApplicationConfigure Application
StudentRecord's Development Directory under NetBeans
Configure Application Configure Application (Cont.)(Cont.)
build.propertiesbuild.properties
Configure Application Configure Application (Cont.)(Cont.)
Build.xmlBuild.xml Server.xmlServer.xml Web.xmlWeb.xml
Configure Application Configure Application (Cont.)(Cont.)
/src/*.java/src/*.java
Configure Application Configure Application (Cont.)(Cont.)
/web/*.jsp/web/*.jsp
Building, Installing, Building, Installing, Deploying Deploying
Use ANT to build, install and deploy Use ANT to build, install and deploy Student Record ApplicationStudent Record Application
Use Neatbeans IDE to build Student Use Neatbeans IDE to build Student Record ApplicationRecord Application
Run ApplicationRun Application
EndEnd
Thank you.Thank you.
Top Related