WEBD4201 Lab 3 Demo
WEBD4201 Lab 3 Demo
Students are encourage to configure their laptops so that the example provided works. This will can become a start
point for Deliverable 3.
Software Setup:
In DC Connect in the “Software” section of the course, download the following:
apache-tomcat-8.0.18-windows-x64.zip
postgresql-9.4-1200.jdbc41.jar
servlet-api.jar
jsp-api.jar
Navigate into the Tomcat8.0/bin folder, right-mouse click on startup.bat and shutdown.bat and “Send
to” -> “Desktop (create shortcut)”
Cut and paste the postgresql-9.4-1200.jdbc41.jar, servlet-api.jar and jsp-api.jar files into the
Tomcat8.0/lib folder.
For Tomcat to run, there needs to be three (3) System environment variable define. Go to Start -> Control
Panel -> System -> Advanced System Settings.
Select the “Advanced” tab, click on “Environment Variables” and under “System variables” create a JAVA_HOME, a
JRE_HOME and CATALINA_HOME variables. Use the browse button to navigate to your JDK and JRE folders in
your C:\Program Files\Java\ directory.
NOTE: the _1.8.0_25 below may differ from the version numbers for your JDK and JRE.
NOTE: if Tomcat does not start up successfully for you, try re-starting your laptop and repeating the last step as the
environmental variables may not have become active yet.
Open a browser and go to localhost:8080, you should be welcomed to the Tomcat welcome page. Click on
“Manager App” in the top right corner, and enter “admin” for user id and nothing for the password (NOTE: the
users are managed WEBD4201 Deliverable 3 Demo
in the Tomcat8.0/conf/tomcat-users.xml file, if you open this file you will see the “admin” role setup).
You should see a few existing applications that Tomcat is already running. One of which is “Manager”, which the is
the manager tool that you have logged in with.
Database Requirements:
In pgAdmin on your laptop, create a new user named db_user if you do not already have one, with a password of
db_password and then assign ownership of a new database named demo_db to that user.
Select the new demo_db and run the SQL script deliverable3_demo/sql/deliverable3_db.sql found in
zip file provided
If you refresh the Manager app at http://localhost:8080/manager/html you should see a new demo
Application. Right-mouse click on the /demo link in the Application paths and click “Open link in new tab”
Java Requirements:
Create a new project in Exclipse named Lab3Example. Import into the src directory *.java files found in the
provided zip file.
In Eclipse: Right mouse-click on your project. Click “Properties -> Java Build Path”. Select “Libraries” tab, and click
“Add External JARs”. Browse to where you have built your Tomcat, go into Tomcat 8.0/lib folder select serlvet-
api.jar and jsp-api.jar and click Open, click Ok
You should be able to build the project into its demo/*.class files. In order for your demo application to use the
files you should place the complete demo folder with its class files contained in the
Tomcat8.0/webapps/demo/WEB-INF/classes folder. Go back to the Tomcat manager and click on the
“Reload” button for the demo application (YOU HAVE TO CLICK “Reload” ANYTIME YOU MAKE A CHANGE TO ANY
CLASS FILE IN THE WEB-INF/classes FOLDER).
NOTE: you should be able to run the provided Lab3DemoTester.java file at this point and get a record back onto
the console.
If you go back to the http://localhost:8080/demo/ page, click on “Login”, and then enter a phone number from the
database (e.g. “123-4567”), it should retrieve the user’s information from the database and display it on the
“customerUpdate.jsp” page.
NOTE: for debug purposes, any System.out.println() method calls in your programs will be displayed in the Tomcat
window.
<servlet>
<servlet-name>UpdateCustomerServlet</servlet-name>
<servlet-class>demo.UpdateCustomerServlet</servlet-class>
</servlet>
The <servlet> element gives a name to a servlet and informs Tomcat where it will be found in the
WEB-INF/classes folder (in this case, there will be a demo package/folder and a LoginServlet.class file there)
<servlet-mapping>
<servlet-name>UpdateCustomerServlet</servlet-name>
<url-pattern>/AnyPattern</url-pattern>
</servlet-mapping>
The <servlet-mapping> element gives the name of a servlet and defines what URL pattern the server will
receive from an HTML form to access the servlet. E.g.