• Homework assignment - HW#3A (Estimate time: 3-6 hours)
    • Objectives
      • Getting exposed to a bit more sophisticated Web application in which the following features of servlets are used
        • Multiple servlets are used
        • A servlet (BannerServlet through /banner) is "included" via RequestDispatcher
        • Servlet filters are used
        • Listener is used
        • JDBC is used to access database table
      • Building and deploying a more advanced Servlet based Web application, bookstore1 of J2EE 1.4 tutorial. The J2EE 1.4 tutorial shows you how to build the same "Duke's Bookstore" sample application using different Web-tier technologies as mentioned below.  In this exercise, you will build bookstore1 using Servlets only. 
        • bookstore1 - using Servlets only
        • bookstore2 - using JSP pages only
        • bookstore3 - using JSP pages and custom tags
        • bookstore4 - using JSP pages and JSTL in native format
        • bookstore5 - using JSP pages and JSTL in XML format
        • bookstore6 - using JavaServer Faces (JSF)

    • Task1  - Build and run bookstore1
      • Build and run "Duke's Bookstore application" bookstore1 example code as described in  "The Examples Servlets section of Chapter 11: Java Servlet Technology" in J2EE 1.4 tutorial.  The build instruction in the tutorial is basically summed up as following: (It would be easier for you to following the instructions below.)
      • Start the App Server.  You can use one of the following 3 options to start the Sun Java System App Server.  (Stopping the App Server works in a similar fashion.  Starting and stopping the App Server can be done in any mix of these options.)
        • Option 1: From the Start menu (Windows platform)
          • Start->All Programs->Sun Microsystems->Application Server PE->Start Default Server
        • Option 2: From the command line
          • Windows: c:\Sun\AppServer\bin\asadmin start-domain domain1 (to start admin server of domain1 and app server instance server1 under domain1)
          • Solaris/Linux: /opt/SUNWappserver/bin/asadmin start-domain domain1 (to start admin server of domain1 and app server instance server1 under domain1)
        • Option 3: Within NetBeans IDE
          • Select Runtime tab
          • Expand Server Registry
          • Right click Sun Java System App Server 8 and select Start/Stop Server
          • If the App Server is not runninging, click Start Server button
      • Start Derby database server (If you are using Sun Java System App Server 8.2) or Pointbase database server (if you are using Sun Java System App Server 8.1).  You can find out what version of Sun Java System App Server is running by "asadmin version".
        • If you are using Sun Java System App Server 8.2, you can one of the following 3 options to start the Derby database server.  (Stopping the database server works in a similar fashion.  Starting and stopping the server can be done in any mix of these options.)
          • Option 1: From the Start menu (Windows platform)
            • Start->All Programs->Sun Microsystems->Application Server PE->Start Derby 
          • Option 2: From the command line
            • Windows: asadmin start-database
            • Solaris/Linux: asadmin stop-database
          • Option 3: Within NetBeans IDE
            • Select Tools->Derby Database->Start Local Derby Database. (If it has been started already, you will see "Start Local Derby Database" grayed out.)
        • If you are using Sun Java System App Server 8.1, you can ue one of the following 2 options to start the Pointbase database server.  (Stopping the database server works in a similar fashion.  Starting and stopping the server can be done in any mix of these options.)
          • Option 1: From the Start menu (Windows platform)
            • Start->All Programs->Sun Microsystems->Application Server PE->Start Pointbase
          • Option 2: From the command line
            • Windows: c:\Sun\AppServer\pointbase\tools\serveroption\startserver.bat
            • Solaris/Linux: /opt/SUNWappserver/pointbase/tools/serveroption/startserver.sh
          • Option 3: Within NetBeans IDE
            • Select Tools->Pointbase Database->Start Local Pointbase Database. (If it has been started already, you will see "Start Local Pontbase Database" grayed out.)
      • Build and package bookstore common files
        • cd c:\j2eetutorial14\examples\web\bookstore
        • asant build (to compile Java source files of the common files)
        • asant package-bookstore (to build bookstore.jar file)
      • Create database tables
        • cd c:\j2eetutorial14\examples\web\bookstore  (if you are not in this directory already)
        • asant create-db_common (to create database tables)
          • (Trouble-shooting)  If this is the first time,  you might see  [sql] Failed to execute:   DROP TABLE BOOKS under delete-db: target.  This is benign.
      • Create Data Source in the App Server
        • cd c:\j2eetutorial14\examples\web\bookstore  (if you are not in this directory already)
        • asant create-jdbc-resource_common
          • (Trouble-shooting)  You might experience the following error " JdbcResource already exists: cannot add duplicate" as shown below if you already have created jdbc/BookDB Data Source in the App Server.  If this happens, just move on to the next step.
            • C:\j2eetutorial14\examples\web\bookstore>asant create-jdbc-resource_common
              Buildfile: build.xml

              create-jdbc-resource_common:

              admin_command_common:
                   [echo] Doing admin task create-jdbc-resource           --connectionpoolid P
              ointBasePool jdbc/BookDB

              [sun-appserv-admin] Executing: create-jdbc-resource --port 4848 --host localhost
               --passwordfile "c:\j2eetutorial14\examples\common\admin-password.txt"  --user a
              dmin           --connectionpoolid PointBasePool jdbc/BookDB

              [sun-appserv-admin] Operation 'createJdbcResource' failed in 'resources' Config
              Mbean.
              [sun-appserv-admin] Target exception message: JdbcResource already exists: canno
              t add duplicate

              BUILD FAILED
              file:C:/j2eetutorial14/examples/common/targets.xml:36: An exception occurred whi
              le running the command.  The exception message is: CLI137 Command create-jdbc-re
              source failed..

              Total time: 2 seconds
            • You can find out if you already have created jdbc/BookDB Data Source in the App Server by taking the following steps:
              • From your browser, go to http://localhost:4848 (to open admin console to the App Server)
              • Enter admin username and password and click Login
              • Expand Resources->JDBC->JDBC Resources.  If you see jdbc/BookDB, then you have already created the jdbc/BookDB.
      • Build bookstore1
        • cd c:\j2eetutorial14\examples\web\bookstore1 (please note that this is ..\bookstore1 not ..\boostore directory)
        • asant build  (to compile Java source files)
      • Deploy bookstore1 application
        • cd c:\j2eetutorial14\examples\web\bookstore1 (if you are not in this directory already)
        • asant create-bookstore-war (to create war file)
        • asant deploy-war
      • Access the bookstore1 application
        • From your browser, go to http://localhost:8080/bookstore1/bookstore. You should see the following picture.

        • Play around with the application to get some sense of which servlet is being invoked


    • Task2 - Understand the bookstore1 application
      • Read documentation of bookstore1 from Chapter 11: Servlet Technology, Section: The Example Servlets of the J2EE 1.4 tutorial.
      • Take a look at the servlets used in this application and see how these servlets are configured in the web.xml file.
        • Windows: dir/s *.java (to search for Java source files)
        • Solaris/Linux: find . -name \*.java -print (to search for Java source files)
      • Take a look at how each user interaction results in invoking a new servlet
      • Take a look at how the banner is being displayed in HTML page that is being displayed to the user
      • Take a look at filters used in this application and how these filters are configured in the web.xml file.
      • Take a look at listeners used in this application and how these listeners are configured in the web.xml file.
      • Please post your questions on the class alias if you have any questions.



  • Homework assignment - HW#3B (Estimate time: 1 hour) - Optional homework
    • Objectives
      • Getting exposed to a more complex Web application in which multiple Servlets are used (with forwarding among themselves)
      • Building and deploying bookstore1 using NetBeans IDE 5.0 leveraging ant build script that comes with the application

    • Task  - Build and run bookstore1 using NetBeans IDE
      • Start NetBeans 5.0 IDE 
      • Start the Derby or Pointbase database server as described in Task 1 above (if it has not been started already - you probably started it already in Task 1)
      • Create a new NetBeans project for bookstore.  The bookstore directory contains Java source files that represent commonly used classes for BookDetails.java.
        • Create a New Project by selecting File from menu and then New Project
        • Under Choose Project pane, select Web and Web Project With Ant Script.  Click Next.
        • Under Name and Location pane,
          • for Location field, select Browse button and browse the directory structure to select the following directory and click Open.
            • <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore
              • Windows: C:\j2eetutorial14\examples\web\bookstore
              • Linux/Solaris: /home/username/j2eetutorial14/examples/web/bookstore
          • Click Next
        • Under Build and Run Actions pane,
          • Click Next
        • Under Web Sources pane,
          • Click Next
        • Under Source Package Folders pane,
          • click Next
        • Under Java Sources Classpath pane,
          • Click Add JAR/Folder.. button.  Under Browse JAR or Folder window, browse to <J2EE_HOME>/lib directory (c:\Sun\AppServer\lib for Windows and /opt/SUNWappserver/lib for Solaris/Linux) and select j2ee.jar and click Open.
          • click Next
        • Under Web Sources Classpath pane,
          • click Finish
        • Observe that a new project node, bookstore, is created under Projects tab window
      • Build and package bookstore common files
        • Expand bookstore node and right click build.xml
        • Right click build.xml and select Run Targets->build
        • Right click build.xml and select Run Targets->package-bookstore
      • Create database tables
        • Right click build.xml and select Run Targets->create-db_common
      • Create a new NetBeans project for bookstore1 application
        • Create a New Project by selecting File from menu and then New Project
        • Under Choose Project pane, select Web and Web Project With Ant Script.  Click Next.
        • Under Name and Location pane,
          • for Location field, select Browse button and browse the directory structure to select the following directory and click Open.
            • <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1
              • Windows: C:\j2eetutorial14\examples\web\bookstore1
              • Linux/Solaris: /home/username/j2eetutorial14/examples/web/bookstore1
          • Click Next
        • Under Build and Run Actions pane,
          • Click Next
        • Under Web Sources pane,
          • for Web Pages Folder field, select Browse button to open file browser and browse the directory structure to select the following directory and click Open
            • <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/web
              • Windows: C:\j2eetutorial14\examples\web\bookstore1\web
              • Linux/Solaris: /home/username/j2eetutorial14/examples/web/bookstore1/web
          • for Context Path field, fill it with /bookstore1
          • for J2EE Specification Level, accept the pre-selected value "J2EE 1.4"
          • Click Next
        • Under Source Package pane,
          • click Next
        • Under Java Sources Classpath pane,
          • Click Add JAR/Folder.. button.  Under Browse JAR or Folder window, browse to <J2EE_HOME>/lib directory (c:\Sun\AppServer\lib for Windows) and select j2ee.jar and click Open.
          • click Next
        • Under Web Sources Classpath pane,
          • click Finish
        • Observe that a new project node, bookstore1-example, is created under Projects tab pane
      • Build, package, and deploy bookstore1-example Web application
        • Expand bookstore1-example node and right click build.xml
        • Right click build.xml and select Run Targets->build
        • Right click build.xml and select Run Targets->create-bookstore-war
        • Add the following two targets to bookstore1-example->build.xml (The reason you are adding these two targets is because deploy-war and undeploy-war would not work.)
          •   <target name="deploy1-war">
                <antcall target="admin_command_common">
                  <param name="admin.command"
                    value="deploy
            ${j2ee.tutorial.home}/examples/web/${example}/${war.file}" />
                </antcall>
              </target>

              <target name="undeploy1-war">
                <antcall target="admin_command_common">
                  <param name="admin.command"
                    value="undeploy
            ${j2ee.tutorial.home}/examples/web/${example}/${war.file}" />
                </antcall>
              </target>
        • Right click build.xml and select Run Targets->Other Targets->deploy1-war
      • Access the bookstore1 application
        • From your browser, go to http://localhost:8080/bookstore1/bookstore
          • (Trouble-shooting) If you see "HTTP Status 404 - Servlet BookStoreServlet is not available" error message, you might have deployed the application when the Pointbase database server is not running.   Do take the following steps to correct the situation.
            • Start the Pointbase database server
            • Right click build.xml and select Run Targets->deploy-war
        • Perform book purchase actions
    • Things to be submitted
      • This is optional so nothing needs to be submitted


  • Homework assignment - HW#3C (Estimate time: 1 to 2 hours) - Optional homework
    • Objectives
      • Building and deploying bookstore1 using NetBeans IDE 5.0 from scratch (without using ant build script that comes with the application), a new ant script is being created by NetBeans
      • Given that you will have to do quite a bit of things in this homework, please be prepared that you might experience a problem or two along the way especially when you skip a step or two.
      • Instead of just cut-and-pasting the code from bookstore1 sample application, please try to write the code yourself first.
    • Task  - Build and run bookstore1 using NetBeans IDE
      • Create a new NetBeans project.
        • Create a New Project by selecting File from menu and then New Project
        • Under Choose Project pane, select Web and Web Application.  Click Next.
        • Under Name and Location pane,
          • for Project Name field, fill it with bookstore1netbeans
          • Click Finish accepting all the default values and selections
        • Observe that bookstore1netbeans project node is created in the Project tab window and default index.jsp gets displayed in the source editor
      • Create servlets: ShowCartServlet, CatalogServlet, BookStoreServlet, CashierServlet, BannerServlet, BookDetailsServlet, ReceiptServlet
        • Create ShowCartServlet
          • Right click bookstore1netbeans project node and select New and select Sevlet.
          • Under Name and Location pane of the New Servlet window,
            • for Class Name field, fill it with ShowCartServlet
            • for Package field, fill it with with servlets.
            • Click Next
          • Under Configure Servlet Deployment pane,
            • for URL Mapping(s) field, change it to /bookshowcart from /ShowCartServlet. 
            • Click Finish
          • Observe that ShowCartServlet.java is displayed in the source editor
          • Replace the NetBeans generated contents of ShowCartServlet.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/servlets/ShowCartServlet.java
            • You can use Favorite window feature of NetBeans for this
        • Create CatalogServlet
          • Right click bookstore1netbeans project node and select New and select Sevlet.
          • Under Name and Location pane of the New Servlet window,
            • for Class Name field, fill it with CatalogServlet
            • for Package field, fill it with with servlets.
            • Click Next
          • Under Configure Servlet Deployment pane,
            • for URL Mapping(s) field, change it to /bookcatalog from /CatalogServlet. 
            • Click Finish
          • Observe that CatalogServlet.java is displayed in the source editor
          • Replace the contents of CatalogServlet.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/servlets/CatalogServlet.java
        • Create BookStoreServlet
          • Right click bookstore1netbeans project node and select New and select Sevlet.
          • Under Name and Location pane of the New Servlet window,
            • for Class Name field, fill it with BookStoreServlet
            • for Package field, fill it with with servlets.
            • Click Next
          • Under Configure Servlet Deployment pane,
            • for URL Mapping(s) field, change it to /bookstore from /BookStoreServlet. 
            • Click Finish
          • Observe that BookStoreServlet.java is displayed in the source editor
          • Replace the contents of BookStoreServlet.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/servlets/BookStoreServlet.java
        • Create CashierServlet
          • Right click bookstore1netbeans project node and select New and select Sevlet.
          • Under Name and Location pane of the New Servlet window,
            • for Class Name field, fill it with CashierServlet
            • for Package field, fill it with with servlets.
            • Click Next
          • Under Configure Servlet Deployment pane,
            • for URL Mapping(s) field, change it to /bookcashier from /CashierServlet. 
            • Click Finish
          • Observe that CashierServlet.java is displayed in the source editor
          • Replace the contents of CashierServlet.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/servlets/CashierServlet.java
        • Create BannerServlet
          • Right click bookstore1netbeans project node and select New and select Sevlet.
          • Under Name and Location pane of the New Servlet window,
            • for Class Name field, fill it with BannerServlet
            • for Package field, fill it with with servlets.
            • Click Next
          • Under Configure Servlet Deployment pane,
            • for URL Mapping(s) field, change it to /banner from /BannerServlet
            • Click Finish
          • Observe that BannerServlet.java is displayed in the source editor
          • Replace the contents of BannerServlet.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/servlets/BannerServlet.java
        • Create BookDetailsServlet
          • Right click bookstore1netbeans project node and select New and select Sevlet.
          • Under Name and Location pane of the New Servlet window,
            • for Class Name field, fill it with BookDetailsServlet
            • for Package field, fill it with with servlets.
            • Click Next
          • Under Configure Servlet Deployment pane,
            • for URL Mapping(s) field, change it to /bookdetails from /BookDetailsServlet
            • Click Finish
          • Observe that BookDetailsServlet.java is displayed in the source editor
          • Replace the contents of BookDetailsServlet.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/servlets/BookDetailsServlet.java
        • Create ReceiptServlet
          • Right click bookstore1netbeans project node and select New and select Sevlet.
          • Under Name and Location pane of the New Servlet window,
            • for Class Name field, fill it with ReceiptServlet
            • for Package field, fill it with with servlets.
            • Click Next
          • Under Configure Servlet Deployment pane,
            • for URL Mapping(s) field, change it to /bookreceipt from /ReceiptServlet
            • Click Finish
          • Observe that ReceiptServlet.java is displayed in the source editor
          • Replace the contents of ReceiptServlet.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/servlets/ReceiptServlet.java
      • Create Filters and a helper class: OrderFilter.java, HitCounterFilter.java, CharResponseWrapper.java
        • Create OrderFilter
          • Right click bookstore1netbeans project node and select New and select File/Folder
          • Under Choose File Type pane, select Web under Categories and Filter under File Types. Click Next.
          • Under Name and Location pane of the New Filter window,
            • for Class Name field, fill it with OrderFilter
            • for Package field, fill it with with filters
            • Select Wrap Request and Response Objects
            • Click Next
          • Under Configure Filter Deployment pane,
            • Click Edit button
          • Under File Mapping dialog box,
            • Select Servlet radio button, and select ReceiptServlet
            • Click OK.
          • Click Finish
          • Observe that OrderFilter.java is displayed in the source editor
          • Replace the contents of OrderFilter.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/filters/OrderFilter.java
        • Create HitCounterFilter
          • Right click bookstore1netbeans project node and select New and select File/Folder
          • Under Choose File Type pane, select Web under Categories and Filter under File Types. Click Next.
          • Under Name and Location pane of the New Filter window,
            • for Class Name field, fill it with HitCounterFilter
            • for Package field, fill it with with filters
            • Select Wrap Request and Response Objects
            • Click Next
          • Under Configure Filter Deployment pane,
            • Click Edit button
          • Under File Mapping dialog box,
            • Select Servlet radio button, and select BookStoreServlet
            • Click OK.
          • Click Finish
          • Observe that HitCounterFilter.java is displayed in the source editor
          • Replace the contents of HitCounterFilter.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/filters/HitCounterFilter.java
        • Create CharResponseWrapper.java
          • Right click bookstore1netbeans project node and select New and select Java Class
          • Under Name and Location pane of the New Java Class window,
            • for Class Name field, fill it with CharResponseWrapper
            • for Package field, fill it with with filters
            • Click Finish
          • Observe that CharResponseWrapper.java is displayed in the source editor
          • Replace the contents of Counter.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/filters/CharResponseWrapper.java
      • Create Listeners: ContextListener
        • Create ContextListener
          • Right click bookstore1netbeans project node and select New and select File/Folder
          • Under Choose File Type pane, select Web under Categories and Web Application Listener under File Types. Click Next.
          • Under Name and Location pane of the New Web Application Listener window,
            • for Class Name field, fill it with ContextListener
            • for Package field, fill it with with listeners
            • for Interfaces to implement, select Context Listener (it's probably already selected as a default).
            • Click Finish
          • Observe that ContextListener.java is displayed in the source editor
          • Replace the contents of ContextListener.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/listeners/ContextListener.java
      • Create utility classes - Counter.java and Currency.java
        • Create Counter.java
          • Right click bookstore1netbeans project node and select New and select Java Class
          • Under Name and Location pane of the New Java Class window,
            • for Class Name field, fill it with Counter
            • for Package field, fill it with with util
            • Click Finish
          • Observe that Counter.java is displayed in the source editor
          • Replace the contents of Counter.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/util/Counter.java
        • Create Currency.java
          • Right click bookstore1netbeans project node and select New and select Java Class
          • Under Name and Location pane of the New Java Class window,
            • for Class Name field, fill it with Currency
            • for Package field, fill it with with util
            • Click Finish
          • Observe that Currency.java is displayed in the source editor
          • Replace the contents of Currency.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/util/Currency.java
      • Create database handler classes - BookDBAO.java
        • Create BookDBAO.java
          • Right click bookstore1netbeans project node and select New and select Java Class
          • Under Name and Location pane of the New Java Class window,
            • for Class Name field, fill it with BookDBAO
            • for Package field, fill it with with database
            • Click Finish
          • Observe that BookDBAO.java is displayed in the source editor
          • Replace the contents of BookDBAO.java with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/src/database/BookDBAO.java
      • Create error page(s), and map exception classess to the error page(s)
        • Create errorpage.html
          • Right click bookstore1netbeans project node and select New and select HTML
          • Under Name and Location pane of the New HTML File window,
            • for HTML File Name field, fill it with errorpage
            • Click Finish
          • Observe that errorpage.html is displayed in the source editor
          • Replace the contents of errorpage.html with the one from <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore1/web/errorpage.html
        • Map exceptions to the errorpage.html
          • Expand bookstore1netbeans project node, expand Web Pages->WEB-INF. Double-click web.xml to open it in the source editor.
          • Select Pages tab window from the right side of the pane
          • Expand Error Pages (if it has not been expanded yet).
          • Map exception.BookNotFoundException
            • Click Add.  The Add Error Page dialog box gets displayed.
            • Under Add Error Page dialog box,
              • for Error Page Location field, click Browse and expand Web Pages and select errorpage.html.  (Don't be alarmed with red-colored warning message and move on.)
              • for Exception Type field, fill it with exception.BookNotFoundException
              • click OK
          • Map exception.BooksNotFoundException (this is different from the BookNotFoundException)
            • Click Add.  The Add Error Page dialog box gets displayed.
            • Under Add Error Page dialog box,
              • for Error Page Location field, click Browse and select Web Pages and select errorpage.html.
              • for Exception Type field, fill it with exception.BooksNotFoundException
              • click OK
          • Map javax.servlet.UnavailableException
            • Click Add.  The Add Error Page dialog box gets displayed.
            • Under Add Error Page dialog box,
              • for Error Page Location field, click Browse and select Web Pages and select errorpage.html.
              • for Exception Type field, fill it with javax.servlet.UnavailableException
              • click OK
      • Add JDBC resource
        • Expand bookstore1netbeans project node, expand Web Pages. Double-click web.xml to open it in the source editor.
        • Select XML
        • Add the following <resource-ref> element right before </web-app> as following.  The code fragment that needs to be added is highlighted with bold font.
          •   <resource-ref>
                <res-ref-name>jdbc/BookDB</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
                <res-sharing-scope>Shareable</res-sharing-scope>
              </resource-ref>
            </web-app>
      • Add bookstore.jar as a runtime library to the bookstore1 project
        • Right click bookstore1netbeans project node and select Properties.  The Project Properties dialog box gets displayed.
        • Under Project Properties dialog box,
          • Select Libraries under Categories and select Add Jar/Folder.  The Add Jar/Folder dialog box gets displayed.
          • Under Add Jar/Folder dialog box, 
            • Browse down to select <j2ee1.4tutorial_install>/j2eetutorial14/examples/web/bookstore/dist/bookstore.jar.
            • Click Open
          • Click OK
      • Copy the GIF file (duke.books.gif) to the application
        • Select Window from menu bar and select Favorites (CTRL+3). The Favorites window allows you to access any file on your computer or network without having create a project for the file.  The Favorites tab window gets created along with Projects, Files, Runtime tab windows.
        • Click Favorites tab window and right click Favorites and select Add to Favorites.
        • Browse the directory to select the <j2ee1.4tutorial_install>/j2eetutorial14/examples/web and click Add button.  Observe that web node is added to the Favorites window.
        • Expand web->bookstore1->web.
        • Select duke.books.gif and right click it and select Copy.
        • Click Projects tab window.
        • Select bookstore1netbeans->Web Pages and right click it and select Paste.  Observe that the duke.books.gif file now is present under Web Pages node.
      • Set the Relative URL of the application
        • Right click bookstore1netbeans project node and select Properties
        • Select Run under Categories
        • For Relative URL field, fill it with /bookstore
      • Build and run the application
        • Right click bookstore1netbeans project node and select Run Project (to compile, deploy, and access the application)
        • Default browser of your system will get displayed automatically accessing the application
          • If the browser does not get popped up, from your browser go to http://localhost:8080/bookstore1netbeans/bookstore  (change the port number 8080 to whatever port number your Sun Java System App Server or Tomcat is using.)
        • (Trouble-shooting) If you enconter HTTP Status 404 -Servlet BookStoreServlet is not available error condition, it is highly likely due to the fact that the database server is not running somehow.  Start the pointbase database server and rerun the application.
    • Things to be submitted
      • This is optional so nothing needs to be submitted
    • NetBeans Features I recommend you to try in this exercise
      • Context sensitive JavaDoc retrieval on any J2EE API
        • Expand bookstore1-example->src->servlets
        • Open one of the Servlet source files, for example, BookStoreServlet.java, in the source editor window by double-clicking it
        • Scroll down the window and move the cursor to string "HttpServlet" and right click it and then select Show Javadoc
        • You will see Java document of the HttpServlet gets displayed in your default browser
        • Try to see Java documents of the other Servlet classes and methods
      • Refactoring
        • Expand bookstore1-example->src->database
        • Open BookDBAO.java in the source editor window by double-clicking it
        • Select "BookDBAO" string and right-click it.  Select Refactor and then select Rename.
        • In the Rename window, fill up the New Name field with "BookDBAONewName" then click Next.
        • On the bottom of the IDE, all the places where changes will be made is shown. Click Do Refactoring button to confirm the refactoring
      • Intelligent string search (find)
        • Note that changes are made to all files where "BookDBAO" is used including BookDBAO.java itself
        • Select the string BookDBAONewName string by double-clicking it. Right-click it and select Find Usages
        • In the Find Usage window, click Next
        • On the bottom of the IDE, under Usage pane, all the usages of BookDBAONewName will be displayed
        • Please do play around this intelligent finding by selecting any string you want and then right-clicking it and then selecting Find Usage
      • HTTP monitoring
        • Enable the Sun Java System App Server 8 for HTTP monitoring (you have to do this only once)
          • Click Runtime pane
          • Expand Runtime->Server Registry
          • Right click Sun Java Sytem Application Server 8 and select Properties
          • Select Enable HTTP Monitor check box
          • Right click Sun Java Sytem Application Server 8 and select Start/Stop Server
          • If the Server is in running state, restart the server by selecting Stop Server and then Start Server button
          • Close the Server Status window by clicking Close button.  HTTP monitoring is now enabled.
        • Open HTTP monitor window
          • Select Windows from munu-bar and select HTTP Monitor
        • Access and run the bookstore1 application
          • From your browser, go to http://localhost:8080/bookstore1/bookstore
          • Perform a few actions
        • Take a look at the captured HTTP traffic
          • In the HTTP monitor window, select one HTTP request or response message
          • You can examine the content, cookie, session, context, client and server, and context information by clicking options on the right pane of the HTTP monitor


  • Homework assignment - HW#3D (Estimate time: 1 to 2 hours) 
    • Objective
      • Exercise servlet filtering scheme
      • You are welcome to use NetBeans to do this homework
    • Task
      • Modify "Duke's Bookstore application" bookstore1 example to add another filter that calculates and display the total "leftover inventory" of ordered books.  (The total inventory of ordered books might not be that much meaningful information and we are using it here for just for the sake of exercising the filtering scheme.)
      • The goal of this exercise is to build a filter.  As long as you build a filter to do this exercise, how you interpret "leftover inventory" and "where you display the information" can be your choice. 
    • Things to be submitted
      • Source code and web.xml file


  • Homework assignment - HW#3E (Estimate time: 1 to 2 hours) 
    • Objective
      • Exercise programming including another web resources in the response
    • Task
      • Use the code and deployment descriptor of HW#2C or HW#2D as a starting point
      • Add your own banner in all your HTTP responses using another servlet
    • Things to be submitted
      • Source code and web.xml file
    • Helpful hints
      • Take a look at "Chapter 11: Java Servlet Technology, Section: Including other resources in your response" from J2EE 1.4 Tutorial (for users using J2EE 1.4 SDK)


  • Homework assignment - HW#3F (Estimate time: 1 to 2 hours) - Optional homework
    • Objective
      • Exercise servlet programming for receiving servlet lifecycle events
    • Tasks
      • Use the code and deployment descriptor of HW#2D as a starting point
      • Write code that capture "Attributed added" events to both Web context and Session
    • Things to be submitted
      • This is optional so there is nothing to be submitted