270 likes | 443 Views
Example. Student Record Application. Environment. Run environment: JDK 1.4 Web server: TOMCAT as JSP container Application Server: pure Java Class Database: Oracle + JDBC driver Development tool NetBeans IDE 3.5.1 ANT+Notepad. Tomcat. Tomcat is a Servlet/JSP container
E N D
Example Student Record Application
Environment • Run environment: JDK 1.4 • Web server: TOMCAT as JSP container • Application Server: pure Java Class • Database: Oracle + JDBC driver • Development tool NetBeans IDE 3.5.1 ANT+Notepad
Tomcat • Tomcat is a Servlet/JSP container • Tomcat implements the Servlet and JavaServer Pages specifications from Java Software
Logic analysis Under the support of Rational XDE
Logic design • Server Side: Servlet + pure java class • Client Side: JSP
Logical Architecture of Server Side Design on J2EE framework Under the support of Rational XDE
ContextListener <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN“ "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <description>Oracle Test App</description> <listener> <listener-class>StudentPackage.contextlisenter</listener-class> </listener> </web-app> Web.xml
Student Record Application Run Cycle • Install or Start StudentRecord Application • Call up JSP • Stop StudentRecord application
Contextlistener start an Application public void contextInitialized(ServletContextEvent sce) { ServletContext sc= sce.getServletContext(); try { StudentPackage.StudentDB studentdb= new StudentPackage.StudentDB(); sc.setAttribute ("studentdb", studentdb); } catch (Exception e) { sc.log ("Couldn't create database attribute: " + e.getMessage ()); } }// end of public void contextInitialized(ServletContextEvent e)
Use StudentDB instance <% StudentPackage.StudentDB studentdb= (StudentPackage.StudentDB) application.getAttribute("studentdb"); Collection students = studentdb.getStudents(); %> Home.jsp
Contextlistener stop an Application public void contextDestroyed(ServletContextEvent sce) { ServletContext sc = sce.getServletContext (); StudentPackage.StudentDB studentdb = (StudentPackage.StudentDB) sc.getAttribute("studentdb"); studentdb.close(); sc.removeAttribute ("studentdb"); }
Prepare Database • Create table CREATE TABLE STUDENTDB ( ID NUMBER(10) NOT NULL PRIMARY KEY, FIRSTNAME VARCHAR2(30) NOT NULL, SURNAME VARCHAR2(30) NOT NULL ); • Insert student record insert into studentdb (id, firstname, surname) values (101,'Emma','Dean');
Configure Application StudentRecord's Development Directory under NetBeans
Configure Application (Cont.) • build.properties
Configure Application (Cont.) • Build.xml • Server.xml • Web.xml
Configure Application (Cont.) • /src/*.java
Configure Application (Cont.) • /web/*.jsp
Building, Installing, Deploying • Use ANT to build, install and deploy Student Record Application • Use Neatbeans IDE to build Student Record Application